How to get ADO .NET command with parameters replaced with values

A

Andrus

I need to get sql command where parameters are replaced by values.
I tried code below but displayed sql statement contains parameter names,
not actual values.

How to obtain command where parameters are replaced by their values ?

Andrus.

static IDataReader ExecuteReader(string command
, out IDbConnection connection
, CommandBehavior behavior
, params IDbDataParameter[] dataParams)
{
connection = ...
connection.Open();
IDbCommand cmd = new SqlCommand(command, connection as
SqlConnection);
foreach (IDbDataParameter p in dataParams)
cmd.Parameters.Add(p);
// How to display replaced parameter values ?
MessageBox.Show(cmd.CommandText);
return cmd.ExecuteReader(behavior |
CommandBehavior.CloseConnection);
}
 
M

Marc Gravell

ADO.NET would never expect to need to do this (since it can pass
parameters, which is safer) - so I doubt there is anything built in.
You will probably need to do your own parse/replace (and escape).

Marc
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top