我用google 搜索了update 的语法,发现以下代码没有错误,在论坛里也搜了一下,以为 Password 为关键字,所以使用[] 程序也报错,我使用的是Delphi 7.0 Access 数据库,Win2000 操作系统,请各位指导一下,谢谢!代码:
ADOQuery1.SQL.Clear;
ADOQuery1.SQL.Add('update WorkNumber set Password=:Password, UserName=:UserName, WorkStatus=:WorkStatus, dayLen=:DayLen,Level=:Level where Id =:Id');
ADOQuery1.Parameters.ParamByName('Password').Value := Trim(Edit2.Text );
ADOQuery1.Parameters.ParamByName('UserName').Value := Trim(Edit3.Text );
ADOQuery1.Parameters.ParamByName('WorkStatus').Value := Trim(ComboBox2.Text );
ADOQuery1.Parameters.ParamByName('DayLen').Value := DateTimePicker1.DateTime;
ADOQuery1.Parameters.ParamByName('Level').Value := Level;
ADOQuery1.Parameters.ParamByName('ID').Value := Id;程序报 Update 语法错误! 百思不得其解!希望大家给指条名路!
ADOQuery1.SQL.Clear;
ADOQuery1.SQL.Add('update WorkNumber set Password=:Password, UserName=:UserName, WorkStatus=:WorkStatus, dayLen=:DayLen,Level=:Level where Id =:Id');
ADOQuery1.Parameters.ParamByName('Password').Value := Trim(Edit2.Text );
ADOQuery1.Parameters.ParamByName('UserName').Value := Trim(Edit3.Text );
ADOQuery1.Parameters.ParamByName('WorkStatus').Value := Trim(ComboBox2.Text );
ADOQuery1.Parameters.ParamByName('DayLen').Value := DateTimePicker1.DateTime;
ADOQuery1.Parameters.ParamByName('Level').Value := Level;
ADOQuery1.Parameters.ParamByName('ID').Value := Id;程序报 Update 语法错误! 百思不得其解!希望大家给指条名路!
还有要用ADOQuery1.ExecSQL
Password=:Password 执行一次
UserName=:UserName 执行一次
。。
看那次出问题
==================================================================
[Password] = :Password, UserName = :UserName, WorkStatus=:WorkStatus, dayLen=:DayLen,[Level]=:Level where [Id] =:Id');加"[]"为MSSQL的保留字,写这等字段的时候最好避免这样的麻烦,例如UPsd表示Password
UName表示UserName,UClass表示Level等
且返回结果集的SQL用 .Open,如SELECT;不返回结果集的用 .ExecSQL,如UPDATE,INSERT,否则运行调试期间会报异常。