Click here to Skip to main content
14,455,338 members
Rate this:
Please Sign up or sign in to vote.
See more:
I have a sql command, and parameters are added to that command. But I can't see how the query looked after the parameters are added. How do I see this query with the parameters added.


What I have tried:

Sqlcommand commconsult = new Sqlcommand(stringconsult, con.connection);
commconsult.parameters.Add("@PARAMETER",txtParam.Text);
Posted
Updated 21-Aug-19 14:05pm
Rate this:
Please Sign up or sign in to vote.

Solution 1

You can't, that's the whole point.
You use parameterised queries to prevent passing a string value to SQL and leaving yourself open to SQL Injection: which means there is no "human readable" or "string version" of the command to look at.

You can always look at the parameters collection of the SqlCommand object manually.
   
Rate this:
Please Sign up or sign in to vote.

Solution 2

Quote:
But I can't see how the query looked after the parameters are added.

That is the point, parameters do not change the query, this is the reason why parameters make the query safe to SQL injection.
Unfortunately, your code do not show the query.
   
Rate this:
Please Sign up or sign in to vote.

Solution 3

If you use the Profiler[^] on the SQL Server, you can see the command as it was sent.
   

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)




CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100