天天看点

delphi连接sql例子

放一个连接组件 ADOConnection 其它组件TADODataSet,TADOQuery等的connection指向ADOConnection就可以了.

function OpenADOConn:boolean;

begin

result:=false;

try

with ADOConnection do

begin

Connected:= false;

Provider:= 'SQLOLEDB.1';

Properties['Data Source'].Value:= HostName; //服务器名

Properties['Initial Catalog'].Value:= DatabaseName; //表名

Properties['User ID'].Value:= UserID; //用户名

Properties['password'].Value:= UserPWD; 密码

LoginPrompt:= false;

try

Connected:= true;

except

begin

Application.MessageBox('无法连结远程数据库!'

,'注意', MB_OK);

exit;

end;

end;

end;

finally

end;

result:=true;

end;