1

I am using Parameters.AddWithValue to my SqlCommand variable.

I am able to dump the output to a textbox by saying

tb.Text = command.CommandText.ToString();

But it's not dumping the value for my parameter into the textbox.

Any suggestions on how to verify the parameters are "ok"?

I am using WinForm for Windows 8 using VS2012

Cocoa Dev
  • 9,361
  • 31
  • 109
  • 177

1 Answers1

4

SQL parameters are sent to the server alongside the text of the command; they are not integrated with the CommandText.

You can examine the parameters by looking at the Value property in the Parameters collection.

SLaks
  • 868,454
  • 176
  • 1,908
  • 1,964
  • How come the value is not being substituted? – Cocoa Dev Feb 15 '13 at 02:08
  • @CocoaDev: Because that's not how SQL Server works. The whole point of using parameters is that the value is **not** substituted; this makes it completely immune to SQL injection and allows the server to better reuse query plans. – SLaks Feb 15 '13 at 14:05
  • So how can I be certain that the parameters values are being substituted. The reason I ask this is I am getting 0 results back. When I run the same exact query in SQL Management Studio, I get data back. Therefore I think one of 2 things. (A) The Parameters.AddWithValue is not being correctly used. (B) something with the how the code is being executed – Cocoa Dev Feb 18 '13 at 14:51
  • I think you misunderstood. I didn't mean substituted for something else. I meant that it being swapped word0 with the actual value that was passed via Parameters – Cocoa Dev Feb 18 '13 at 14:53