我做了一个数据库查询程序,用的是ADO,包括ADOConnection,ADOQuery,ADOTable,Datasource,Gbgrid等组件,我希望数据库的连接能在程序运行时应用程序能根据运行路径来找到,所以我把数据库zhengduanxue放在一个data文件夹中,代码如下:
procedure TForm1.FormCreate(Sender: TObject);
var
mypath:string;
begin
//table:='zhengduanxue';
mypath:=extractfilepath(paramstr(0));
shortdateformat:='yyyy/mm/dd';
adoconnection1.ConnectionString:='provider=microsoft.jet.oledb.4.0;datasource='+mypath+'\诊断学.mdb';
//adoquery1.Connection:=adoconnection1;
//adotable1.Connection:=adoconnection1;
adotable1.TableName:='zhengduanxue';
adotable1.Active:=true;
adoquery1.SQL.Add('select * from zhengduanxue');
adoquery1.Active:=true;
datasource1.DataSet:=adoquery1;
dbgrid1.DataSource:=datasource1;
end;
但有错误,请高手帮帮忙啊!我这是最后10分了!如能帮我,请留下QQ,在线等啊!