我是个Delphi新手,各位大哥大姐们快帮帮我. 请问在Delphi中不通过ODBC数据源,如何与SQL SERVER连接. 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 ADO------------------你是用Delphi 5.0以上的版本吧 同上,看看我的连接代码吧.这是连接SQL2000的unit Unit1;interfaceuses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, StdCtrls, DB, ADODB;type TForm1 = class(TForm) ADOConnection1: TADOConnection; labelededit1: TEdit; labelededit2: TEdit; Button1: TButton; Button2: TButton; Label1: TLabel; Label2: TLabel; Edit1: TEdit; Label3: TLabel; Edit2: TEdit; Label4: TLabel; procedure Button1Click(Sender: TObject); procedure Button2Click(Sender: TObject); private { Private declarations } public { Public declarations } end;var Form1: TForm1;implementation{$R *.dfm}procedure TForm1.Button1Click(Sender: TObject);varstr:string;beginif (labelededit1.Text<>'') and (labelededit2.Text<>'') thenbegin//连接远程服务器:str:='Provider=SQLOLEDB.1'+';'+'Persist Security Info=False'+';'+'User ID='+LabeledEdit1.Text+';'+'Password='+labelededit2.text+';'+'Initial Catalog=数据库名称'+';'+'Data Source=服务器名称';str:='Provider=SQLOLEDB.1'+';'+'Persist Security Info=False'+';'+'User ID='+LabeledEdit1.Text+';'+'Password='+labelededit2.text+';'+'Initial Catalog='+edit2.Text+';'+'Data Source='+EDIT1.Text;ADOConnection1.ConnectionString:=str;ADOConnection1.Open;labelededit2.Text:='';Button1.Enabled:=false;end;end;procedure TForm1.Button2Click(Sender: TObject);beginADOConnection1.Close;Button1.Enabled:=true;end;end.下一篇::用ADOConnection连接到具体数据库: procedure Tloginmain.Button1Click(Sender: TObject);varstr:string;beginif (labelededit1.Text<>'') and (labelededit1.Text<>'') thenbegin//连接远程服务器:str:='Provider=SQLOLEDB.1'+';'+'Persist Security Info=False'+';'+'User ID='+LabeledEdit1.Text+';'+'Password='+labelededit2.text+';'+'Initial Catalog=数据库名称'+';'+'Data Source=服务器名称';str:='Provider=SQLOLEDB.1'+';'+'Persist Security Info=False'+';'+'User ID='+LabeledEdit1.Text+';'+'Password='+labelededit2.text+';'+'Initial Catalog=testdase';ADOConnection1.ConnectionString:=str;ADOConnection1.Open;labelededit2.Text:='';end;end;断开数据库:procedure Tloginmain.Button2Click(Sender: TObject);beginADOConnection1.Close;Button1.Enabled:=true; end;具体连接到数据库的某个表可以用:ADODataSet将ADODataSet的Connection属性设置为:ADOConnection将ADODataSet的CommandType属性设置为:cmdTableif not loginmain.ADODataSet1.Active thenbeginADODataSet1.CommandText:='worker_information';//worker_information为表名ADODataSet1.Open;end; 现在最新版的Delphi是什么版本啊?Delphi.NET是什么? 急啊!!!有谁做过fastreport打印曲线图?? 测试我的东东 文本框输入日期 请教一个有关数据库字段显示在DBGrid控件中的问题。 记录类型问题 ToolBar的问题真是烦人? 请问如何在选中combobox下拉菜单中的一项时显示一个表的内容? 语句有问题吗? 关于数据库操作中AppendRecord错误,请各位朋友指教。 三层,如何实现设置代理服务器程序,高手请进 ***用image.picture.bitmap.canvas.textout()写出文字,怎样对他进行移动??
你是用Delphi 5.0以上的版本吧
这是连接SQL2000的unit Unit1;interfaceuses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, DB, ADODB;type
TForm1 = class(TForm)
ADOConnection1: TADOConnection;
labelededit1: TEdit;
labelededit2: TEdit;
Button1: TButton;
Button2: TButton;
Label1: TLabel;
Label2: TLabel;
Edit1: TEdit;
Label3: TLabel;
Edit2: TEdit;
Label4: TLabel;
procedure Button1Click(Sender: TObject);
procedure Button2Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;var
Form1: TForm1;implementation{$R *.dfm}procedure TForm1.Button1Click(Sender: TObject);
var
str:string;
begin
if (labelededit1.Text<>'') and (labelededit2.Text<>'') then
begin
//连接远程服务器:str:='Provider=SQLOLEDB.1'+';'+'Persist Security Info=False'+';'+'User ID='+LabeledEdit1.Text+';'+'Password='+labelededit2.text+';'+'Initial Catalog=数据库名称'+';'+'Data Source=服务器名称';str:='Provider=SQLOLEDB.1'+';'+'Persist Security Info=False'+';'+'User ID='+LabeledEdit1.Text+';'+'Password='+labelededit2.text+';'+'Initial Catalog='+edit2.Text+';'+'Data Source='+EDIT1.Text;ADOConnection1.ConnectionString:=str;ADOConnection1.Open;labelededit2.Text:='';
Button1.Enabled:=false;end;end;procedure TForm1.Button2Click(Sender: TObject);
begin
ADOConnection1.Close;Button1.Enabled:=true;end;end.
下一篇::
用ADOConnection连接到具体数据库: procedure Tloginmain.Button1Click(Sender: TObject);varstr:string;beginif (labelededit1.Text<>'') and (labelededit1.Text<>'') thenbegin//连接远程服务器:str:='Provider=SQLOLEDB.1'+';'+'Persist Security Info=False'+';'+'User ID='+LabeledEdit1.Text+';'+'Password='+labelededit2.text+';'+'Initial Catalog=数据库名称'+';'+'Data Source=服务器名称';str:='Provider=SQLOLEDB.1'+';'+'Persist Security Info=False'+';'+'User ID='+LabeledEdit1.Text+';'+'Password='+labelededit2.text+';'+'Initial Catalog=testdase';ADOConnection1.ConnectionString:=str;ADOConnection1.Open;labelededit2.Text:='';end;end;断开数据库:
procedure Tloginmain.Button2Click(Sender: TObject);beginADOConnection1.Close;Button1.Enabled:=true; end;
具体连接到数据库的某个表可以用:ADODataSet将ADODataSet的Connection属性设置为:ADOConnection将ADODataSet的CommandType属性设置为:cmdTableif not loginmain.ADODataSet1.Active thenbeginADODataSet1.CommandText:='worker_information';//worker_information为表名ADODataSet1.Open;end;