String:=' Provider=Microsoft.Jet.OLEDB.4.0; ' +' Data Source= '+ExtractFilePath(ParamStr(0))+'database\ISI.mdb; ' +' Persist Security Info=False; '; ADOConnection1.ConnectionString:=String; try ADOConnection1.Connected:=true; except Application.MessageBox('数据库连接不成功,确认数据库的路径是否正确!','提示',64); Form_Main.Close; // 退出程序 end;// end of try 得到ConnectionString的方法: 双击ADOConnection1,点Build,一步步的选择连接的数据库,测试连接成功后,把Provider拷贝出来,就是了
怎么没有人理我,你们是怎么连接数据库的,,看看我的程序: procedure TForm1.Button1Click(Sender: TObject); var conn:_connection; res:_Recordset; strSql:string; begin StrConn:='Provider=SQLOLEDB.1;Password="";Persist Security Info=True;' +'User ID=sa;Initial Catalog=pubs;Data Source=huangq'; conn.ConnectionString:=StrConn; //ADOConnection1 strSql:='select * from employee'; res := conn.Execute(strSql,1);//(strSql,,0) ;//这个地方我不知道怎么写,,给一个解决方法 while not res.EOF do begin showMessage(res.Fields.Item[0].Value); end; end;
String:=' Provider=Microsoft.Jet.OLEDB.4.0; '
+' Data Source= '+ExtractFilePath(ParamStr(0))+'database\ISI.mdb; '
+' Persist Security Info=False; ';
ADOConnection1.ConnectionString:=String;
try
ADOConnection1.Connected:=true;
except
Application.MessageBox('数据库连接不成功,确认数据库的路径是否正确!','提示',64);
Form_Main.Close; // 退出程序
end;// end of try
得到ConnectionString的方法:
双击ADOConnection1,点Build,一步步的选择连接的数据库,测试连接成功后,把Provider拷贝出来,就是了
procedure TForm1.Button1Click(Sender: TObject);
var
conn:_connection;
res:_Recordset;
strSql:string;
begin
StrConn:='Provider=SQLOLEDB.1;Password="";Persist Security Info=True;'
+'User ID=sa;Initial Catalog=pubs;Data Source=huangq';
conn.ConnectionString:=StrConn;
//ADOConnection1 strSql:='select * from employee';
res := conn.Execute(strSql,1);//(strSql,,0) ;//这个地方我不知道怎么写,,给一个解决方法
while not res.EOF do
begin
showMessage(res.Fields.Item[0].Value);
end;
end;