插入VALUES()问题 [英] Insert into VALUES() question

查看:73
本文介绍了插入VALUES()问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述




如何在

插入命令的VALUES()部分中插入变量而不是值,即


var1 = 10;

var2 = 20;

var3 = 30

插入emp_test (emp_no1,emp_no2,emp_no3)VALUES(var1,var2,var3)" ;;


以上不起作用。


TIA

Roy

Hi,

How can I insert variables instead of values in the VALUES() part of the
insert into command, i.e.

var1=10;
var2=20;
var3=30

insert into emp_test (emp_no1, emp_no2, emp_no3) VALUES (var1, var2, var3)";

The above does not work.

TIA
Roy

推荐答案

var1 = 10;

var2 = 20;

var3 = 30


" insert into emp_test(emp_no1,emp_no2,emp_no3)VALUES(" + var1 +"," +

var2 +"," + var3 +")" ;;


这样的动态sql对sql注入攻击是开放的。小心......


-

Robbe Morris - 2004/2005 Microsoft MVP C#
http://www.masterado.net

Roy Gourgi < RO *** @ videotron.ca>在消息中写道

新闻:Ha ********************* @ weber.videotron.net ..。
var1=10;
var2=20;
var3=30

"insert into emp_test (emp_no1, emp_no2, emp_no3) VALUES (" + var1 + "," +
var2 + "," + var3 + ")";

dynamic sql like this is wide open to sql injection attacks. Be careful...

--
Robbe Morris - 2004/2005 Microsoft MVP C#
http://www.masterado.net

"Roy Gourgi" <ro***@videotron.ca> wrote in message
news:Ha*********************@weber.videotron.net.. .


如何在
插入命令的VALUES()部分中插入变量而不是值,即

var1 = 10;
var2 = 20;
var3 = 30
插入emp_test(emp_no1,emp_no2,emp_no3)VALUES(var1,var2,
var3)" ;;

以上不起作用。

TIA
Roy
Hi,

How can I insert variables instead of values in the VALUES() part of the
insert into command, i.e.

var1=10;
var2=20;
var3=30

insert into emp_test (emp_no1, emp_no2, emp_no3) VALUES (var1, var2,
var3)";

The above does not work.

TIA
Roy






***通过开发人员指南 http://www.developersdex.com ***


*** Sent via Developersdex http://www.developersdex.com ***


Robbe Morris [C#MVP]< in ** @ eggheadcafe.com>写道:
Robbe Morris [C# MVP] <in**@eggheadcafe.com> wrote:
var1 = 10;
var2 = 20;
var3 = 30
"插入emp_test(emp_no1,emp_no2,emp_no3)VALUES (+ var1 +,+
var2 +,+ var3 +)" ;;
这样的动态sql对sql注入是开放的攻击。小心......
var1=10;
var2=20;
var3=30

"insert into emp_test (emp_no1, emp_no2, emp_no3) VALUES (" + var1 + "," +
var2 + "," + var3 + ")";

dynamic sql like this is wide open to sql injection attacks. Be careful...




这就是你应该使用SQL参数的原因。如果你将SQL

参数名称放入VALUES子句中,那么设置参数

本身,你不需要在SQL中包含任何用户提供的数据

声明。


-

Jon Skeet - < sk *** @ pobox.com>
http://www.pobox.com/~skeet 博客: http://www.msmvps.com/jon.skeet

如果回复小组,请不要给我发邮件



Which is why you should use SQL parameters instead. If you put the SQL
parameter names into the VALUES clause, then set the parameters
themselves, you don''t need to include any user-provided data in the SQL
statement.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too


这篇关于插入VALUES()问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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