大家有没有动态建立adoconnection,adotable的代码,我写的老是出错。帮分析以下也可。(100分)

Y

yaxexe

Unregistered / Unconfirmed
GUEST, unregistred user!
各位大虾给分析以下错误的原因。
提示“miss connection or connectstring”

var
adoconnection1:TAdoconnection;
adotable1:Tadotable;
begin
adoconnection1:=TAdoconnection.Create(nil);
adotable1:=TAdotable.Create(nil);

try
with adoconnection1 do
begin
ConnectionString:='Provider=SQLOLEDB.1;Persist Security
info=False;User ID=sa;Initial Catalog=wlks;Data Source=ASKGOD';
connected:=true;
loginprompt:=false;
open('sa','');
end;

if adotable1.active then adotable1.close;
adotable1.name:='alluser';
adotable1.open;/****就是一执行到这句就出错,去掉就可以了*****/
//adotable1.active:=true;
showmessage('正确联结数据库');
except
SHOWMESSAGE('失敗!');
end;
 
你的create里面一定要加self
要不然怎么知道她的父是谁?!
 
加:

adotable1.connection :=adoconnection1;
 
if adotable1.active then adotable1.close;
adotable1.connection :=adoconnection1 ;<加上>
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
adotable1.name:='alluser';
adotable1.open;/****就是一执行到这句就出错,去掉就可以了*****/
//adotable1.active:=true;
showmessage('正确联结数据库');
except
SHOWMESSAGE('失敗!');
end;
 
adotable1.Connection:=adoconnection1;
 
adotable1.connection := adoconnection1;
或者:
adotable1.connectionstring := adoconnection1.connectionstring;
 
adotable1.Connection:=adoconnection1;
 
同意,没有数据集连接
 
我已经调试过了:是连接的我自己的SQL SERVER
var
adoconnection1: TAdoconnection;
adotable1: Tadotable;
begin
adoconnection1 := TAdoconnection.Create(nil);
adotable1 := TAdotable.Create(nil);
with adoconnection1 do
begin
loginprompt := false; //要放在连接前定义才有用
ConnectionString := 'Provider=SQLOLEDB.1;Password=00;Persist Security'
+' Info=True;User ID=gg;Initial Catalog=CGXCLIENT;Data Source=WG';//连接的我自己的Sql server
connected := true;

end;
adotable1.connection := adoconnection1;
adotable1.name := 'alluser';
adotable1.TableName := 'sendman'; //连接数据表sendman,我自己的
try
adotable1.open;
except
showmessage('连接数据库出错');
exit;
end;
//adotable1.open;//就是一执行到这句就出错,去掉就可以了
//adotable1.active:=true;
showmessage('正确联结数据库');
 
把楼上的代码改一下
adoconnection1 := TAdoconnection.Create(nil);
adotable1 := TAdotable.Create(nil);
改为
adoconnection1 := TAdoconnection.Create(self);
adotable1 := TAdotable.Create(self);

adotable1.name := 'alluser';没有用。
 
只要先放个控件在FORM里面,然后删除就行了,楼上的一个意思,
不过是优化了
 
分析以下错误的原因。
提示“miss connection or connectstring”

看到没有,数据库没有连接,这是因为缺少一句:adoconnection1.connected:=true;
这样连上数据库,错误提示就应该没有了。
拓荒者的办法应该是可以的。
yaxexe, 看来不常用ado,否则adoconnection1.connected:=true;怎么就忘了呢?!
 
对呀,你的adoquery没和adoconnection连接而且你的adoquery没有返回数据集怎么能打开呢?
 
各位大虾,如果我都更正正确,而且在form里测试也是正确的,那么我把他作成dll,可是调用时老是出现错误“尚未调用Cointialize”
请分析以下好吗?
 
已经给分,注意查收!
 
顶部