P
Puma Wang
Unregistered / Unconfirmed
GUEST, unregistred user!
我在Delphi 6 里想做一个实现定时读取数据库和修改数据库的小工控控件,
我 如下代码 老是在adcMaster.Execute 提示 :
“[Microsoft][ODBC 驱动程序 管理器] 未发现数据源名称并且未指定默认驱动程序”
的错误。
数据库是 SQL Server 7.0 和2000 试过都一样的错。以下是简单的示意代码 :
interface
uses
Windows, Messages, SysUtils, Classes, Controls, ExtCtrls,ADODB;
type
TTestPanel = class(TCustomPanel)
private
{ Private declarations }
Timer1 :TTimer ;
adcMaster :TADOCommand ;
FConnection :TADOConnection ;
FTimerEnabled: Boolean;
Procedure DoUpdate(sender :TOBject) ;
procedure SetTimerEnabled(const Value: Boolean);
procedure SetConnection(const Value: TADOConnection);
procedure SetadcMaster ;
procedure SetTimer ;
procedure SetConn ;
protected
{ Protected declarations }
public
{ Public declarations }
Constructor Create(AOwner :TComponent) ;override ;
Destructor Destroy ;override ;
published
{ Published declarations }
property TimerEnabled :Boolean Read FTimerEnabled write SetTimerEnabled Default True ;
property Connection :TADOConnection Read FConnection Write SetConnection ;
end;
procedure Register;
implementation
procedure Register;
begin
RegisterComponents('PumaTestLable', [TTestPanel]);
end;
{ TTestPanel }
constructor TTestPanel.Create(AOwner: TComponent);
begin
inherited Create(AOwner);
SetAdcMaster ;
SetTimer ;
SetConn ;
end;
destructor TTestPanel.Destroy;
begin
if assigned(Timer1) then Timer1.Destroy ;
if assigned(adcMaster) then adcMaster.Destroy ;
inherited;
end;
procedure TTestPanel.DoUpdate(sender: TOBject);
begin
if (assigned(FConnection)) and FConnection.Connected then
Begin
adcMaster.CommandText :='insert into OnHand Values ('+ Quotedstr('003') +
',getDate(),'+Quotedstr('This is Address')+')' ;
adcMaster.Execute ; // 就这里出错!!!!!
End ;
end;
procedure TTestPanel.SetadcMaster;
begin
if (assigned(adcMaster)) then exit ;
if csDesigning in ComponentState then exit ;
adcMaster :=TADOCommand.Create(self);
if assigned(FConnection) then
adcMaster.Connection :=FConnection ;
end;
procedure TTestPanel.SetConn;
begin
if not assigned(Connection) then
Begin
FConnection :=TADOConnection.Create(self) ;
FConnection :=Connection ;
if assigned(adcMaster) then
adcMaster.Connection :=FConnection ;
End ;
end;
procedure TTestPanel.SetConnection(const Value: TADOConnection);
begin
FConnection := Value;
end;
procedure TTestPanel.SetTimer;
begin
if csDesigning in ComponentState then exit ;
Timer1 :=TTimer.Create(self);
Timer1.Interval :=1000 ;
Timer1.OnTimer :=DoUpdate ;
Timer1.Enabled :=True ;
end;
procedure TTestPanel.SetTimerEnabled(const Value: Boolean);
begin
FTimerEnabled := Value;
end;
end.
兄弟们 帮我看看。
我 如下代码 老是在adcMaster.Execute 提示 :
“[Microsoft][ODBC 驱动程序 管理器] 未发现数据源名称并且未指定默认驱动程序”
的错误。
数据库是 SQL Server 7.0 和2000 试过都一样的错。以下是简单的示意代码 :
interface
uses
Windows, Messages, SysUtils, Classes, Controls, ExtCtrls,ADODB;
type
TTestPanel = class(TCustomPanel)
private
{ Private declarations }
Timer1 :TTimer ;
adcMaster :TADOCommand ;
FConnection :TADOConnection ;
FTimerEnabled: Boolean;
Procedure DoUpdate(sender :TOBject) ;
procedure SetTimerEnabled(const Value: Boolean);
procedure SetConnection(const Value: TADOConnection);
procedure SetadcMaster ;
procedure SetTimer ;
procedure SetConn ;
protected
{ Protected declarations }
public
{ Public declarations }
Constructor Create(AOwner :TComponent) ;override ;
Destructor Destroy ;override ;
published
{ Published declarations }
property TimerEnabled :Boolean Read FTimerEnabled write SetTimerEnabled Default True ;
property Connection :TADOConnection Read FConnection Write SetConnection ;
end;
procedure Register;
implementation
procedure Register;
begin
RegisterComponents('PumaTestLable', [TTestPanel]);
end;
{ TTestPanel }
constructor TTestPanel.Create(AOwner: TComponent);
begin
inherited Create(AOwner);
SetAdcMaster ;
SetTimer ;
SetConn ;
end;
destructor TTestPanel.Destroy;
begin
if assigned(Timer1) then Timer1.Destroy ;
if assigned(adcMaster) then adcMaster.Destroy ;
inherited;
end;
procedure TTestPanel.DoUpdate(sender: TOBject);
begin
if (assigned(FConnection)) and FConnection.Connected then
Begin
adcMaster.CommandText :='insert into OnHand Values ('+ Quotedstr('003') +
',getDate(),'+Quotedstr('This is Address')+')' ;
adcMaster.Execute ; // 就这里出错!!!!!
End ;
end;
procedure TTestPanel.SetadcMaster;
begin
if (assigned(adcMaster)) then exit ;
if csDesigning in ComponentState then exit ;
adcMaster :=TADOCommand.Create(self);
if assigned(FConnection) then
adcMaster.Connection :=FConnection ;
end;
procedure TTestPanel.SetConn;
begin
if not assigned(Connection) then
Begin
FConnection :=TADOConnection.Create(self) ;
FConnection :=Connection ;
if assigned(adcMaster) then
adcMaster.Connection :=FConnection ;
End ;
end;
procedure TTestPanel.SetConnection(const Value: TADOConnection);
begin
FConnection := Value;
end;
procedure TTestPanel.SetTimer;
begin
if csDesigning in ComponentState then exit ;
Timer1 :=TTimer.Create(self);
Timer1.Interval :=1000 ;
Timer1.OnTimer :=DoUpdate ;
Timer1.Enabled :=True ;
end;
procedure TTestPanel.SetTimerEnabled(const Value: Boolean);
begin
FTimerEnabled := Value;
end;
end.
兄弟们 帮我看看。