begin
try
   ADOConnection1.BeginTrans;
   ADOQuery1.SQL.Clear;
   ADOQuery1.SQL.Add('Insert into t_one(userID,UserName,UserPass)values(:userid,:username,:userpass)');
   ADOQuery1.Parameters[0].Value := 1;
   ADOQuery1.Parameters[1].Value := 'James';
   ADOQuery1.Parameters[2].Value := '12345';
   ShowMessage(ADOQuery1.SQL.Text);
   ADOQuery1.Prepared := true;
   ADOQuery1.Post;
   ADOConnection1.CommitTrans;
   ShowMessage('Sucess');
except
   ADOConnection1.RollbackTrans;
   ShowMessage('Fail');
end;
end;请问我的代码错了吗?,我反复提交, 为什么不能异常保护,注明:UserID为关键字
正确的代码是什么?

解决方案 »

  1.   

    ADOQuery1.ExecSQL
    很聪明,本身就没有打开你post什么?执行sql语句啦
      

  2.   

    With Data.QUERY1  do
       begin
       close ;
       sql.Clear ;
       sql.Add ('insert SHI(TITLE,CONTENT,DATE_C) values(:a,:b,:c)') ;
       Parameters.parambyname('a').Value:= Trim(Edit1.Text) ;
       Parameters.parambyname('b').Value:= Memo1.Text ;
       Parameters.parambyname('c').Value:= edit2.Text ;
       ExecSQL ;
       close ;
       end ;
    看看这里
      

  3.   

    ADOQuery1.ExecSQL!!最好將出錯的信息貼出來.
      

  4.   

    begin
    try
       ADOConnection1.BeginTrans;
       ADOQuery1.Close;//********************
       ADOQuery1.SQL.Clear;
       ADOQuery1.SQL.Add('Insert into t_one(userID,UserName,UserPass)values(:userid,:username,:userpass)');
       ADOQuery1.Parameters[0].Value := 1;//*******Key!!不能重复,要修改
       ADOQuery1.Parameters[1].Value := 'James';
       ADOQuery1.Parameters[2].Value := '12345';
       ShowMessage(ADOQuery1.SQL.Text);
       ADOQuery1.Prepared := true;
       ADOQuery1.ExecSQL;//**************************
       ADOConnection1.CommitTrans;
       ShowMessage('Sucess');
    except
       ADOConnection1.RollbackTrans;
       ShowMessage('Fail');
    end;
    end;