下面是程序CODE,
unit demo3;interfaceuses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, ExtCtrls, DBCtrls, Grids, DBGrids, DB, ADODB;type
TForm1 = class(TForm)
ADOConnection1: TADOConnection;
ADODataSet1: TADODataSet;
DataSource1: TDataSource;
DBGrid1: TDBGrid;
DBNavigator1: TDBNavigator;
rgFieldNames: TRadioGroup;
cbSearchValue: TComboBox;
Button1: TButton;
ADODataSet2: TADODataSet;
procedure ADODataSet1AfterOpen(DataSet: TDataSet);
procedure Button1Click(Sender: TObject);
procedure rgFieldNamesClick(Sender: TObject);
private
{ Private declarations }
procedure FillFieldNames;
procedure FillSearchValues;
function GetSearchField:string;
public
{ Public declarations }
end;var
Form1: TForm1;implementation{$R *.dfm}
procedure TForm1.FillFieldNames;
var
iCount:integer;
begin
rgFieldNames.Items.Clear;
for iCount:=0 to ADODataSet1.Fields.Count-1 do
begin
rgFieldNames.Items.Add(ADODataSet1.Fields[iCount].FieldName);
end;
rgFieldNames.ItemIndex:=0;
end;
function TForm1.GetSearchField:string;
begin
result:=ADODataSet1.Fields[rgFieldNames.ItemIndex].fieldName;
end;procedure TForm1.FillSearchValues;
begin
try
ADODataSet2.close;
ADODataSet2.commandText:='select '+GetSearchField +
'from 客户';
ADODataSet2.Open;
cbSearchValue.Items.clear;
while not ADODataSet2.EOF do
begin
cbSearchValue.items.add(ADODataSet2.Fields[0].AsString);
ADODataSet2.Next;
end;
finally
ADODataSet2.close;
end;
end;
procedure TForm1.ADODataSet1AfterOpen(DataSet: TDataSet);
begin
FillFieldNames;
FillSearchValues;
end;procedure TForm1.rgFieldNamesClick(Sender: TObject);
begin
FillSearchValues;
end;procedure TForm1.Button1Click(Sender: TObject);
begin
ADODataSet1.Locate(GetSearchField,cbSearchValue.Text,
[loCaseInsensitive,loPartialKey]);end;
end.报错:
missing connection or connectionstring
请问如何解决
unit demo3;interfaceuses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, ExtCtrls, DBCtrls, Grids, DBGrids, DB, ADODB;type
TForm1 = class(TForm)
ADOConnection1: TADOConnection;
ADODataSet1: TADODataSet;
DataSource1: TDataSource;
DBGrid1: TDBGrid;
DBNavigator1: TDBNavigator;
rgFieldNames: TRadioGroup;
cbSearchValue: TComboBox;
Button1: TButton;
ADODataSet2: TADODataSet;
procedure ADODataSet1AfterOpen(DataSet: TDataSet);
procedure Button1Click(Sender: TObject);
procedure rgFieldNamesClick(Sender: TObject);
private
{ Private declarations }
procedure FillFieldNames;
procedure FillSearchValues;
function GetSearchField:string;
public
{ Public declarations }
end;var
Form1: TForm1;implementation{$R *.dfm}
procedure TForm1.FillFieldNames;
var
iCount:integer;
begin
rgFieldNames.Items.Clear;
for iCount:=0 to ADODataSet1.Fields.Count-1 do
begin
rgFieldNames.Items.Add(ADODataSet1.Fields[iCount].FieldName);
end;
rgFieldNames.ItemIndex:=0;
end;
function TForm1.GetSearchField:string;
begin
result:=ADODataSet1.Fields[rgFieldNames.ItemIndex].fieldName;
end;procedure TForm1.FillSearchValues;
begin
try
ADODataSet2.close;
ADODataSet2.commandText:='select '+GetSearchField +
'from 客户';
ADODataSet2.Open;
cbSearchValue.Items.clear;
while not ADODataSet2.EOF do
begin
cbSearchValue.items.add(ADODataSet2.Fields[0].AsString);
ADODataSet2.Next;
end;
finally
ADODataSet2.close;
end;
end;
procedure TForm1.ADODataSet1AfterOpen(DataSet: TDataSet);
begin
FillFieldNames;
FillSearchValues;
end;procedure TForm1.rgFieldNamesClick(Sender: TObject);
begin
FillSearchValues;
end;procedure TForm1.Button1Click(Sender: TObject);
begin
ADODataSet1.Locate(GetSearchField,cbSearchValue.Text,
[loCaseInsensitive,loPartialKey]);end;
end.报错:
missing connection or connectionstring
请问如何解决
ado的connect没连接或连接错了
设置ADODataSet1的connection为ADOConnection1
'from 客户';
这个地方出了问题
我总觉得GetSearchField在程序开启的时候有点问题
设置ADODataSet1、ADODataSet2的connection为ADOConnection1
肯定是这的问题
你再调调
而且用ADOConnection1连库时测试一下看看是否连接成功!!!