unit ado;interfaceuses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, DB, Grids, DBGrids, ADODB, StdCtrls;type
Tmain = class(TForm)
ADOConnection1: TADOConnection;
ADOQuery1: TADOQuery;
DBGrid1: TDBGrid;
DataSource1: TDataSource;
Button1: TButton;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;var
main: Tmain;implementation{$R *.dfm}procedure Tmain.Button1Click(Sender: TObject);
const
part1='Provider=MSDASQL;Persist Security Info=False;Extended Properties="DBQ=';
part2=';DefaultDir=';
part3=';Driver={Driver do Microsoft Access (*.mdb)};DriverId=25;FIL=MS Access;MaxBufferSize=2048;MaxScanRows=8;PageTimeout=5;SafeTransactions=0;Threads=3;UID=admin;UserCommitSync=Yes;"';
var
appPath:string;
begin
if(button1.Caption='连接') then
begin
appPath:=extractFilePath(application.ExeName);
ADOConnection1.ConnectionString:=part1+appPath+'db.mdb'+part2+appPath+part3;
ADOConnection1.Open;
ADOQuery1.SQL.Text:='select * from users';
ADOQuery1.Open;
button1.Caption:='断开'
end
else
begin
button1.Caption:='连接'
ADOQuery1.Close; //提示这句有错误,为什么?!!!
ADOConnection1.Close;
endend;
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, DB, Grids, DBGrids, ADODB, StdCtrls;type
Tmain = class(TForm)
ADOConnection1: TADOConnection;
ADOQuery1: TADOQuery;
DBGrid1: TDBGrid;
DataSource1: TDataSource;
Button1: TButton;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;var
main: Tmain;implementation{$R *.dfm}procedure Tmain.Button1Click(Sender: TObject);
const
part1='Provider=MSDASQL;Persist Security Info=False;Extended Properties="DBQ=';
part2=';DefaultDir=';
part3=';Driver={Driver do Microsoft Access (*.mdb)};DriverId=25;FIL=MS Access;MaxBufferSize=2048;MaxScanRows=8;PageTimeout=5;SafeTransactions=0;Threads=3;UID=admin;UserCommitSync=Yes;"';
var
appPath:string;
begin
if(button1.Caption='连接') then
begin
appPath:=extractFilePath(application.ExeName);
ADOConnection1.ConnectionString:=part1+appPath+'db.mdb'+part2+appPath+part3;
ADOConnection1.Open;
ADOQuery1.SQL.Text:='select * from users';
ADOQuery1.Open;
button1.Caption:='断开'
end
else
begin
button1.Caption:='连接'
ADOQuery1.Close; //提示这句有错误,为什么?!!!
ADOConnection1.Close;
endend;
解决方案 »
- indy10中IDFTP的神奇问题
- 共享摄像头编程?
- 请问borland公司先后出的paradox和delphi有什么区别?很急
- 一个treeview的显示问题!
- 简单问题,答者有分,急,在线等!
- 请问谁有用query从两个表中查数据,然后用updatesql更新回数据库的程序
- 关于TIF格式文件在delphi6中预览的问题
- Delphi中Webservice的调用
- ***********倒底有没有懂fileread??????????
- 在 DLL 创建窗体的办法,CREATEFORM();不可以用,立即给分,谢谢。。。
- 如何让MDI程序每打开一个子窗口就在工具栏添加一个按钮,关闭该子窗口则相应的按钮删除?
- 我想做一个发邮件的程序,D5的,怎么得到邮件服务器的信息啊?
if(button1.Caption='连接') then
begin
appPath:=extractFilePath(application.ExeName);
ADOConnection1.ConnectionString:=part1+appPath+'db.mdb'+part2+appPath+part3;
ADOConnection1.Open;
ADOQuery1.SQL.Text:='select * from users';
ADOQuery1.Open;
button1.Caption:='断开'
end
else
begin
button1.Caption:='连接'
ADOQuery1.Close; //提示这句有错误,为什么?!!!
ADOConnection1.Close;
endend;
------------------
这句没有问题
用Microsoft Jet 4.0吧, 应该不会有问题的
在执行BUTTON的click事件时,AdoConnection1.open/close就行了。
你出错的地方是不是你的ADOQUERY没有connection值吧。
begin
ADOConnection1.ConnectionString := 'Provider=Microsoft.Jet.OLEDB.4.0;'+'Data Source=db.mdb;Persist Security Info=False';
if(button1.Caption='连接') then
begin
ADOConnection1.Open;
ADOQuery1.SQL.Text:='select * from users';
ADOQuery1.Open;
button1.Caption:='断开'
end
else
begin
button1.Caption:='连接'
ADOQuery1.Close; //依旧是关闭错误!!???
ADOConnection1.Close;
endend;
end.
begin
ADOConnection1.ConnectionString := 'Provider=Microsoft.Jet.OLEDB.4.0;'+'Data Source=db.mdb;Persist Security Info=False';
ADOQuery1.SQL.Text:='select * from users';
if(button1.Caption='连接') then
begin
ADOConnection1.Open;
ADOQuery1.Open;
button1.Caption:='断开'
end
else
begin
ADOQuery1.Close;
ADOConnection1.Close;
button1.Caption:='连接'
endend;
end.调试通过,但在运行EXE文件时,ADO可以打开,段断开时出现异常“对象打开,操作不被允许”,这是为什么??
begin
ADOConnection1.ConnectionString := 'Provider=Microsoft.Jet.OLEDB.4.0;'+'Data Source=db.mdb;Persist Security Info=False';
ADOQuery1.SQL.Text:='select * from users';
if(button1.Caption='连接') then
begin
ADOConnection1.Open;
ADOQuery1.Open;
button1.Caption:='断开'; //后面加一个分号
end
else
begin
ADOQuery1.Close;
ADOConnection1.Close;
button1.Caption:='连接'
endend;
end.