如何使用insert查询使用参数? [英] How use the insert query using parameters?

查看:248
本文介绍了如何使用insert查询使用参数?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我尝试使用这个查询,我得到一个错误,说Perameter电子邮件不存在,我确定变量:email,login_pass,payment_method,operatingur是有效的和存在。

  SQLQuery2.sql.Text:='INSERT INTO registered(email,login_pass,payment_method,operatingur)VALUES(:email,:login_pass,:payment_method ,:avecpuce)'; 
SQLQuery2.ParamByName('email')。AsString:= email;
SQLQuery2.ParamByName('login_pass')。AsString:= login_pass;
SQLQuery2.ParamByName('payment_method')。AsString = = payment_method;
SQLQuery2.ParamByName('avecpuce')。AsString:= avecpuce;
SQLQuery2.ExecSQL(true);

我尝试删除报价,但我得到



您的Sql语法中有错误,请检查与SQL服务器对应的手册,以获取正确的语法以使用
'附近:email,:login_pass,:payment_method, avecpuce)'在第1行


如何使用参数上面的插入查询?

解决方案

找到答案!

  MySQLQuery2.SQL.Clear; 
MySQLQuery2.SQL.Add('INSERT INTO COUNTRY(NAME,CAPITAL,POPULATION)');
MySQLQuery2.SQL.Add('VALUES(:Name,:Capital,,Population)');
MySQLQuery2.Params [0] .AsString:='利希滕斯坦';
MySQLQuery2.Params [1] .AsString:='Vaduz';
MySQLQuery2.Params [2] .AsInteger:= 420000;
MySQLQuery2.ExecSQL;

谢谢所有!!


When i try with this query i get an error says that Perameter email doesn't exist, i am sure that the variables : email, login_pass, payment_method,operateur are valid and exists.

SQLQuery2.sql.Text := 'INSERT INTO registered (email,login_pass,payment_method,operateur) VALUES (":email",":login_pass",":payment_method",":avecpuce")';
SQLQuery2.ParamByName('email').AsString := email;
SQLQuery2.ParamByName('login_pass').AsString := login_pass;
SQLQuery2.ParamByName('payment_method').AsString := payment_method;
SQLQuery2.ParamByName('avecpuce').AsString := avecpuce;
SQLQuery2.ExecSQL(true);

I tried removing the quotation, but i get

You have an error in your Sql syntax, check the manual that corresponds to your SQL server for the right syntax to use near ':email,:login_pass,:payment_method,:avecpuce)' at line 1

How to use the insert query above using parameters?

解决方案

Found the answer !

MySQLQuery2.SQL.Clear;
MySQLQuery2.SQL.Add('INSERT INTO COUNTRY (NAME, CAPITAL, POPULATION)');
MySQLQuery2.SQL.Add('VALUES (:Name, :Capital, :Population)');
MySQLQuery2.Params[0].AsString := 'Lichtenstein';
MySQLQuery2.Params[1].AsString := 'Vaduz';
MySQLQuery2.Params[2].AsInteger := 420000;
MySQLQuery2.ExecSQL;

Thankyou All !!

这篇关于如何使用insert查询使用参数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆