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

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Andrus

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

    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(s tring command
    , out IDbConnection connection
    , CommandBehavior behavior
    , params IDbDataParamete r[] dataParams)
    {
    connection = ...
    connection.Open ();
    IDbCommand cmd = new SqlCommand(comm and, connection as
    SqlConnection);
    foreach (IDbDataParamet er p in dataParams)
    cmd.Parameters. Add(p);
    // How to display replaced parameter values ?
    MessageBox.Show (cmd.CommandTex t);
    return cmd.ExecuteRead er(behavior |
    CommandBehavior .CloseConnectio n);
    }

  • Marc Gravell

    #2
    Re: How to get ADO .NET command with parameters replaced with values

    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

    Comment

    Working...