连的是access数据库,提示update语法错误!!(我看不出哪儿错,把,改成and居然不报错,不过username的值总是0)
procedure TForm1.Button1Click(Sender: TObject);
begin
with ADOQuery1 do
begin
adoquery1.close;
adoquery1.sql.clear;
adoquery1.sql.add('select * from logmember where username=');
adoquery1.sql.add(''''+edit1.Text+''''+' and password=');
adoquery1.sql.add(''''+edit2.Text+'''');
adoquery1.open;
if recordcount>=1 then
begin
if (edit3.Text<>'') and (edit4.Text <> '') then
begin
adoquery1.sql.clear;
adoquery1.sql.add('update logmember set username=');
adoquery1.sql.add(''''+trim(edit3.Text)+''''+',');
adoquery1.sql.add('password='+''''+trim(edit4.Text)+'''');
ADOQuery1.ExecSQL;
end;
end;
end;
end;
end.
procedure TForm1.Button1Click(Sender: TObject);
begin
with ADOQuery1 do
begin
adoquery1.close;
adoquery1.sql.clear;
adoquery1.sql.add('select * from logmember where username=');
adoquery1.sql.add(''''+edit1.Text+''''+' and password=');
adoquery1.sql.add(''''+edit2.Text+'''');
adoquery1.open;
if recordcount>=1 then
begin
if (edit3.Text<>'') and (edit4.Text <> '') then
begin
adoquery1.sql.clear;
adoquery1.sql.add('update logmember set username=');
adoquery1.sql.add(''''+trim(edit3.Text)+''''+',');
adoquery1.sql.add('password='+''''+trim(edit4.Text)+'''');
ADOQuery1.ExecSQL;
end;
end;
end;
end;
end.
解决方案 »
- 接管程序的OnException?接管窗体的OnException?
- listview
- 赚分,速结
- 搜索了CSDN的资料宝库,还是不能解决的高难问题-----有关快捷方式和ShellExecuteEx!!
- 将word文件保存到数据库,然后下载到本地,通过CreateOLEObject('Word.Application')打开,但每次总是打开两个word
- 如何根据access表中不同记录的kmdm字段值计算出dfkm值?
- ★★★CSDN结贴联盟第1次信誉提问!!★★★
- 高手帮忙,怎样把用DELPHI 5. 0写的程序,转到DELPHI 6.0中
- 请问WINDOWS中日期/时间中的数字表,有UP/DOWN按钮,可方便地调整时间,如何实现?
- 如何在主窗口与About窗之间传输少量数据?
- 一个sql语句问题!!!
- 如何在打印时用记录中的这个字段判断???
begin
with ADOQuery1 do
begin
adoquery1.close;
adoquery1.sql.clear;
adoquery1.sql.add('select * from logmember where username='''+edit1.Text+''' and password='''+edit2.Text+'''');
adoquery1.open;
if recordcount>=1 then
begin
if (edit3.Text<>'') and (edit4.Text <> '') then
begin
adoquery1.close;
adoquery1.sql.clear;
adoquery1.sql.add('update logmember set username='''+trim(edit3.Text)+''', password='''+trim(edit4.Text)+'''');
ADOQuery1.ExecSQL;
end;
end;
end;
end;
end.试试吧
adoquery1.sql.add('update logmember set username='''+trim(edit3.Text)+''', password='''+trim(edit4.Text)+'''');
这可是把所有记录的内容都改了啊,你难道不是想改一条?另外,主要是‘’的问题,用好了就行了。
adoquery1.sql.add('update logmember set username='+#39+trim(edit3.Text)+#39+'and password='+#39+trim(edit4.Text)+#39);
ADOQuery1.ExecSQL;
为了避免使用引号套引号,使用#39,表示引号,这样肯定没错
adoquery1.sql.add(''''+edit1.Text+''''+' and password=');
adoquery1.sql.add(''''+edit2.Text+'''');
你的语句产生的sql语句是:
select * from logmember where username=
'user1' and password=
'pass0'
注:edit1.text := 'user1'; edit2.text := 'pass0';
这样在'user1'前有一个换行符
if (edit3.Text<>'') and (edit4.Text <> '') then
begin
//在重新操作adoquery1前应该关闭close它
adoquery1.Close; //add
......
end;
end;
begin
with ADOQuery1 do
begin
adoquery1.close;
adoquery1.sql.clear;
adoquery1.sql.add('select * from logmember where username=');
adoquery1.sql.add(''''+edit1.Text+''' and password=');
adoquery1.sql.add(''''+edit2.Text+'''');
adoquery1.open;
if recordcount>=1 then
begin
if (edit3.Text<>'') and (edit4.Text <> '') then
begin
adoquery1.sql.clear;
adoquery1.sql.add('update logmember set username=');
adoquery1.sql.add(''''+trim(edit3.Text)+''',');
adoquery1.sql.add('password='''+trim(edit4.Text)+'''');
ADOQuery1.ExecSQL;
end;
end;
end;
end;
end.
主要原因是你的"'"號的太多了。