sql,增加一条记录提示有错,代码如下.看看是哪里写错了.(50分)

  • 主题发起人 主题发起人 塬上独狼
  • 开始时间 开始时间

塬上独狼

Unregistered / Unconfirmed
GUEST, unregistred user!
procedure TForm1.Button4Click(Sender: TObject);<br>begin<br>adoquery1.sql.clear;<br><br>ADOQuery1.SQL.Add('insert &nbsp; into &nbsp; water1 &nbsp; (开支用户) &nbsp; values('''+Edit1.Text+''')');<br>ADOQuery1.ExecSQL;<br>adoquery1.open;<br><br><br>end;
 
ADOQuery1.ExecSQL;<br>adoquery1.open;<br>间加入了<br>adoquery1.sql.clear;<br>adoquery1.sql.text := 'select * from water1';
 
procedure TForm1.Button4Click(Sender: TObject);<br>begin<br>adoquery1.close;<br>adoquery1.sql.clear;<br><br>ADOQuery1.SQL.Add('insert &nbsp; into &nbsp; water1 &nbsp; (开支用户) &nbsp; values('''+Edit1.Text+''')');<br>ADOQuery1.ExecSQL;<br>adoquery1.close;<br>adoquery1.sql.clear;<br>adoquery1.sql.add('select * from water1');<br>adoquery1.open;<br><br><br>end;
 
ADOQuery1.SQL.Add('insert &nbsp; into &nbsp; water1 &nbsp; ([开支用户]) &nbsp; values('''+Edit1.Text+''')');
 
adoquery1.sql.clear;<br><br>ADOQuery1.SQL。text:='insert &nbsp; into &nbsp; water1 &nbsp; (开支用户) &nbsp; values('''+Edit1.Text+''')';<br>ADOQuery1.ExecSQL;
 
adoquery1.sql.clear;<br>ADOQuery1.SQL。text:='insert &nbsp; into &nbsp; water1 &nbsp; (开支用户) &nbsp; values('''+Edit1.Text+''')';<br>ADOQuery1.ExecSQL;//增加 &nbsp;<br>ADOQuery1.SQL。text:='select * from water1';<br>ADOQuery1.open;//增加后查询一次,也就是刷新
 
提示有错,是因为在没有关闭Query之前,你将Sql Clear了。<br>执行后,需要重新将SQL赋值,再OPEN
 
with adoquery1 do<br>&nbsp;begin <br>&nbsp; &nbsp;close;<br>&nbsp; &nbsp;sql.clear;<br>&nbsp; &nbsp;SQL.text:='insert into water1 (开支用户) values &nbsp;'''+Edit1.Text+''')';<br>&nbsp; &nbsp;ExecSQL;<br>&nbsp; &nbsp;close;<br>&nbsp; &nbsp;sql.text:='select * from water1';<br>&nbsp; &nbsp;open;<br>&nbsp; end;
 
adoquery1.close;<br>adoquery1.sql.clear;<br>ADOQuery1.SQL.Add('insert &nbsp; into &nbsp; water1 &nbsp; (开支用户) &nbsp; values('''+Edit1.Text+''')');<br>ADOQuery1.ExecSQL;<br>这样就行了,下面还要加个open,没用。open是针对select的,insert,delete,update用execsql
 
procedure TForm1.Button4Click(Sender: TObject);<br>begin<br>adoquery1.Close;<br>adoquery1.sql.clear;<br>ADOQuery1.SQL.Add('insert &nbsp; into &nbsp; water1 &nbsp; (开支用户) &nbsp; values('''+Edit1.Text+''')');<br>ADOQuery1.ExecSQL;<br>end;
 
还有一个原因,当Edit1.Text中的值有'的时候,也会出错。所以最好用<br>ADOQuery1.SQL.Add('insert &nbsp; into &nbsp; water1 &nbsp; ([开支用户]) &nbsp; values('+QuotedStr(Edit1.Text)+')');
 
ADOQuery1.ExecSQL;<br>adoquery1.open;<br><br>建議樓主回去看下書先 !!!
 
后退
顶部