请帮我看看如下一段代码错在哪里? (0分)

B

billson

Unregistered / Unconfirmed
GUEST, unregistred user!
With DataModule1.ADOQuery1 do
begin
close;
sql.Clear;
sql.Add('select FAccountName from TBas_Account where FAccountName='''
+txtUser.Text+'''');
open;
If Not Eof Then frmPub.ShowMessage('存在该用户,无法添加用户!')
else
begin
insert();
Recordset.Fields.Item['FAccountName'].Value :=txtUser.Text;
Recordset.Fields.Item['FAccountPwd'].Value :=txtPwd.Text;
UpdateRecord;
end;
end;
 
With DataModule1.ADOQuery1 do
begin
close;
sql.Clear;
sql.Add('select FAccountName,faccountpwd from TBas_Account where FAccountName='''
+txtUser.Text+'''');
open;
If Not Eof Then frmPub.ShowMessage('存在该用户,无法添加用户!')
else
begin
insert();
Recordset.Fields.Item['FAccountName'].Value :=txtUser.Text;
Recordset.Fields.Item['FAccountPwd'].Value :=txtPwd.Text;
UpdateRecord;
end;
end;
 
to 豆豆:
什么意思啊?
 
With DataModule1.ADOQuery1 do
begin
close;
sql.Clear;
**** sql.Add('select FAccountName from TBas_Account where FAccountName='+''''
+txtUser.Text+'''');
open;
If Not Eof Then frmPub.ShowMessage('存在该用户,无法添加用户!')
else
begin
insert();
Recordset.Fields.Item['FAccountName'].Value :=txtUser.Text;
Recordset.Fields.Item['FAccountPwd'].Value :=txtPwd.Text;
UpdateRecord;
end;
end;
 
当用到EOF时,是否要先要first;再while not eof then begin....next;end;呢?
仅供参考!
 
我现在想插入一个新行,如果while not eof then没有达到要求啊
 
这个问题看起来不难啊,请各位delphier出出手吧
 
。。。。
 
什么错误提示的?
 
错误的行在以下几行:
insert();
Recordset.Fields.Item['FAccountName'].Value :=txtUser.Text;
Recordset.Fields.Item['FAccountPwd'].Value :=txtPwd.Text;
UpdateRecord;

是报EOF或BOF的错误,是不是insert不对?
 
这样试试吧:
With DataModule1.ADOQuery1 do
begin
close;
sql.Clear;
**** sql.Add('select FAccountName from TBas_Account where FAccountName='+''''
+txtUser.Text+'''');
open;
first; //Add
If Not Eof Then frmPub.ShowMessage('存在该用户,无法添加用户!')
else
begin
{
insert();
Recordset.Fields.Item['FAccountName'].Value :=txtUser.Text;
Recordset.Fields.Item['FAccountPwd'].Value :=txtPwd.Text;
UpdateRecord;
}
sql.clear;
sql.add('insert into tablename values('''+ txtUser.Text +''','''+ txtPwd.Text +'''');
EXECSQL;
end;
end;
 
似乎是Delphi的那个Bug
 
to noswing
你的select 后少了个字段facontpwd
 
是的,不过后来我在SQL语句中加上了该字段后,仍然报错
 
估计你没在ADOQuery1设永久性字段
 
你的语句没问题,一点问题都没有!!!!!!!!!!
你把ado升级到最高版本,问题就解决了,这是delphi的ado封装的问题(只要
adoquery的记录为空,再用时就出现这个问题)
或者用bde问题也可解决!!
你看看办吧!
 
建议:
With DataModule1.ADOQuery1 do
begin
close;
sql.Clear;
sql.Add('select FAccountName from TBas_Account where FAccountName='''
+txtUser.Text+'''');
open;
If Not Empty Then //
frmPub.ShowMessage('存在该用户,无法添加用户!')
else begin
close;
sql.Clear;
sql.add('insert into tablename values('''+ txtUser.Text +''','''+ txtPwd.Text +'''');
EXECSQL;
end;
end;
 
后来我把程序也改成了“填海精卫”所建议的那样,能顺利通过,但我不想使用sql语句来
插入记录,想通过使用Recordset集来实现这种操作,不知有没有好的方法?
 

Similar threads

S
回复
0
查看
3K
SUNSTONE的Delphi笔记
S
S
回复
0
查看
2K
SUNSTONE的Delphi笔记
S
I
回复
0
查看
569
import
I
I
回复
0
查看
3K
import
I
S
回复
0
查看
846
SUNSTONE的Delphi笔记
S
顶部