连接 with ADOConnection1 do begin Close; ConnectionString:='Provider=SQLOLEDB.1;Persist Security Info=False;User ID=sa;Initial Catalog=AD;Data Source='+fString +';Use Procedure for Prepare=1;Auto Translate=True;Packet Size=4096'; try Open; except Application.MessageBox(PChar('对不起!与您所指定服务器 '+fString+' 的连接失败!'#13#10+'可能的原因是:'#13#10+' 一、指定的服务器已经关机。'#13#10+' 二、SQL Server服务器已经停止运行。'#13#10+' 三、没有安装必须的数据库。'#13#10+' 四、没有拨号连接远程服务器'#13#10+'请您与有关的网络管理人员联系。'),'提示信息',MB_OK + MB_ICONEXCLAMATION); Exit; end; end; with adoquery1 do begin connection:=ADOConnection1 ; if active=true then active:=false; sql.clear; sql.add('sql语句'); ExecSQL; end;
我以前是搞vb的,公司要用delphi开发,时间很紧,能在详细些吗?在多给些例子吧!谢了!
连接就不说了, with query1 do begin Close; SQL.Clear; SQL.Add('select ... from .... where .....'); Open; end; //打开数据集 增加: with Query1 do begin Append; //内容 Post; end; 编辑: with Query1 do begin Edit; //内容 Post; end; 删除: Query1.delete;
with ADOConnection1 do
begin
Close;
ConnectionString:='Provider=SQLOLEDB.1;Persist Security Info=False;User ID=sa;Initial Catalog=AD;Data Source='+fString +';Use Procedure for Prepare=1;Auto Translate=True;Packet Size=4096';
try
Open;
except
Application.MessageBox(PChar('对不起!与您所指定服务器 '+fString+' 的连接失败!'#13#10+'可能的原因是:'#13#10+' 一、指定的服务器已经关机。'#13#10+' 二、SQL Server服务器已经停止运行。'#13#10+' 三、没有安装必须的数据库。'#13#10+' 四、没有拨号连接远程服务器'#13#10+'请您与有关的网络管理人员联系。'),'提示信息',MB_OK + MB_ICONEXCLAMATION);
Exit;
end;
end;
with adoquery1 do
begin
connection:=ADOConnection1 ;
if active=true then
active:=false;
sql.clear;
sql.add('sql语句');
ExecSQL;
end;
with query1 do
begin
Close;
SQL.Clear;
SQL.Add('select ... from .... where .....');
Open;
end; //打开数据集
增加:
with Query1 do
begin
Append;
//内容
Post;
end;
编辑:
with Query1 do
begin
Edit;
//内容
Post;
end;
删除:
Query1.delete;