Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

SqlCommand Parameterized query problems

0 views
Skip to first unread message

benson.wong

unread,
Nov 17, 2009, 2:34:07 AM11/17/09
to
such as the following code :
...
string insertsql="INSERT INTO table (id,name) VALUES (@id,@name)";
SqlCommand cmd=new SqlCommand(insertsql,connection);
cmd.Parameters.Add(@id,1);
cmd.Parameters.Add(@name,"benson");

cmd.ExecuteNonQuery();


How do I get a real SQL? cmd.CommandText get "INSERT INTO table (id,name)
VALUES (@id,@name)",
I hope to have "INSERT INTO table (id,name) VALUES (1,'benson')"

Sakura

unread,
Nov 19, 2009, 4:12:34 AM11/19/09
to
Greetings, benson.wong

You must know that SQL engine will execute parameterized query in a
different way, it does not expand the parameter to a whole SQL query then
execute it, but the engine will deal with each argument with the type it
defined as.

So parameterized queries do not have a direct method to change into a
query text, because it does not need to.

"benson.wong" <tinybe...@hotmail.com> д����Ϣ
news:EA6DCC3C-3525-4626...@microsoft.com...

0 new messages