我想用ADOQUERY控件往SQL数据库中添加记录,但不知为何运行时老提示出错.请各位帮忙.
adoquery1.Close;
adoquery1.SQL.Clear;
adoquery1.SQL.add('insert into thing1(number,name,department,ip)');
adoquery1.SQL.Add('values (:number,:name,:department,:ip)');
adoquery1.Parameters.ParamByName('number').Value := inttostr(i);
adoquery1.Parameters.ParamByName('name').Value := combobox1.Text;
adoquery1.Parameters.ParamByName('department').Value :=combobox2.Text;
adoquery1.Parameters.ParamByName('ip').Value := combobox3.Text;
try
adoquery1.Open;
except
adoquery1.ExecSQL;
end;
adoquery1.Close;
adoquery1.SQL.Clear;
adoquery1.SQL.add('insert into thing1(number,name,department,ip)');
adoquery1.SQL.Add('values (:number,:name,:department,:ip)');
adoquery1.Parameters.ParamByName('number').Value := inttostr(i);
adoquery1.Parameters.ParamByName('name').Value := combobox1.Text;
adoquery1.Parameters.ParamByName('department').Value :=combobox2.Text;
adoquery1.Parameters.ParamByName('ip').Value := combobox3.Text;
try
adoquery1.Open;
except
adoquery1.ExecSQL;
end;
解决方案 »
- delphi 运算错误 请问如何定义浮点型的变量?
- FastReport 显示字段内容如何进行换行
- [来者有分]急问题:用过MMTools的过来哦 其中MMOscope或者MMSpectrum在或者MMSpectrogram这些控件问题
- 关于DBGRIDEH 多行显示的问题
- Somebody Help Me!......
- 请问在Delphi里要怎么样才能格式化某个盘!!在线等!
- 所以我求求你 ado SQL Server 2000
- 给一个人事管理系统的解决方案!
- 取文件大小和时间的方法或函数
- 用OPENROWSET 把EXCEL导入ACCESS时出FROM附近有语法错误~~~在线等~~~
- Delphi is nothing comparing to Java!!!!!!
- 求助:delphi编写ASP组件的方法
adoquery1.ExecSQL;
except
showmessage('error');
end;
个人感觉用adoquery1.append比写insert好一些!
对于你的代码,name用[name]代替实现试试;还有,输入的数据是否有:出现ip)'->ip) ',留个空格再看看
执行insert等操作时只能用ExecSQL而不能用open ,
你的几个字段名可能和关键字有处突,在写sql的时候把每个字段用[]括起来。adoquery1.SQL.add('insert into thing1(number,name,department,ip)');
adoquery1.SQL.Add('values (:number,:name,:department,:ip)');
这两句之间没有空格,应该在values前加空格
adoquery1.SQL.Clear;
adoquery1.SQL.add('insert into thing1(number,name,department,ip)');
adoquery1.SQL.Add(' values (:number,:name,:department,:ip)');
adoquery1.Parameters.ParamByName('number').Value := inttostr(i);
adoquery1.Parameters.ParamByName('name').Value := combobox1.Text;
adoquery1.Parameters.ParamByName('department').Value :=combobox2.Text;
adoquery1.Parameters.ParamByName('ip').Value := combobox3.Text;
adoquery1.ExecSQL;
end;空格
直接用EexecSQL
ADOQuery1.FieldValues['字段名']:=值;
..
..
ADOQuery1.Post;
再看看是不是修改了关键字
你直接运行exe应该就不报错了!