F
Flashcqxg
Unregistered / Unconfirmed
GUEST, unregistred user!
我将我的代码贴出来,大家帮我看看吧,我的疑问都写在注释里面了,谢谢大家:<br>unit Unit1;<br><br>interface<br><br>uses<br> Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,<br> Dialogs, StdCtrls, DB, ADODB;<br><br>type<br> TForm1 = class(TForm)<br> ADOConnection1: TADOConnection;<br> ADOQuery1: TADOQuery;<br> Button1: TButton;<br> Button2: TButton;<br> procedure Button1Click(Sender: TObject);<br> procedure Button2Click(Sender: TObject);<br> private<br> { Private declarations }<br> public<br> { Public declarations }<br> end;<br><br>var<br> Form1: TForm1;<br><br>implementation<br><br>{$R *.dfm}<br><br>procedure TForm1.Button1Click(Sender: TObject);<br>begin<br><br> if ADOConnection1.Connected then<br> ShowMessage('连接上了的')<br> else<br> begin<br> ShowMessage('将连接数据库');<br> ADOConnection1.ConnectionString := 'Provider=MSDASQL.1;Password=sq;Persist Security Info=True;User ID=sa;Data Source=test';<br> ADOConnection1.KeepConnection := True;<br> ADOConnection1.Open;<br><br> ADOQuery1.Connection := ADOConnection1;<br> ADOQuery1.Close;<br> ADOQuery1.SQL.Clear;<br> ADOQuery1.SQL.Add('select * from sys_users');<br> ADOQuery1.Open;<br> ShowMessage(IntToStr(ADOQuery1.RecordCount));<br> ADOQuery1.Close;<br> end;<br><br>end;<br><br>procedure TForm1.Button2Click(Sender: TObject);<br>begin<br> ADOQuery1.Connection := nil;<br> ADOQuery1.Active := False;<br> ADOConnection1.Close;<br> ADOConnection1.KeepConnection := False;<br>//如果这里真正断开了,那么下面的语句应该出错才对呀?<br><br> ADOQuery1.Connection := ADOConnection1;<br> ADOQuery1.Close;<br> ADOQuery1.SQL.Clear;<br> ADOQuery1.SQL.Add('select * from sys_users');<br> ADOQuery1.Open;<br> ShowMessage(IntToStr(ADOQuery1.RecordCount));<br> //但这里又有正确的结果?????<br><br>end;<br><br>end.