我想用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
- delphi7插入数据有个字段要做判断,要求不要用参数的形式,还有什么方法?
- 请教一个用Inno打包的问题
- 祝福奶奶,顺便为我工作满2年纪念!
- 用TIdFtpClient连接服务器,怎样释放端口
- 用线程搜索目录下的文件,应该算是多线程的问题吧。请大侠们帮忙!
- 网上的XP风格的皮肤控件都是怎么做的?
- 将Excel表中的数据导入Sql server的速度最快方案(用程序中实现)
- 奇怪的菜单问题!
- >>>>>>谁帮我解决这个线程问题,全分(380)相赠!
- 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应该就不报错了!