问题描述
unit Unit1;
interface
使用
Windows,消息,SysUtils,变体,类,图形,控件,表格,
Dialogs,StdCtrls,DB,ADODB;
类型
TForm1 = class(TForm)
ADOConnection1:TADOConnection;
Button1: TButton;
编辑1:TEdit;
程序Button1Click(发件人:TObject);
私人
{私人声明}
public
{公共声明}
结束;
var
Form1:TForm1;
实施
{$ R * .dfm }
程序TForm1.Button1Click(发件人:TObject);
var
s:string;
开始
如果adoconnection1.connected那么
开始
adoconnection1.Connected:= false;
结束其他
开始
s:= adoconnection1.ConnectionString;
s:= adodb.PromptDataSource(self.Handle,s);
adoconnection1.ConnectionString:= s;
尝试
adoconnection1.connected:= true;
除了
结束;
结束;
Edit1.text:= s;
结束;
结束。
我尝试了什么:
我有这个访问数据库的代码我希望sql server的代码相同谢谢
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, DB, ADODB;
type
TForm1 = class(TForm)
ADOConnection1: TADOConnection;
Button1: TButton;
TEdit;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
procedure TForm1.Button1Click(Sender: TObject);
var
s : string;
begin
if adoconnection1.connected then
begin
adoconnection1.Connected:=false;
end else
begin
s := adoconnection1.ConnectionString;
s := adodb.PromptDataSource(self.Handle, s);
adoconnection1.ConnectionString := s;
try
adoconnection1.connected:=true;
except
end;
end;
Edit1.text := s;
end;
end.
What I have tried:
I have this code for access database i want the same code for sql server thanks
推荐答案
这篇关于如何动态连接SQL Server到delphi的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!