For logging purposes, I’m afraid there’s no nicer way of doing this but to construct the string yourself:
string query = cmd.CommandText;
foreach (SqlParameter p in cmd.Parameters)
{
query = query.Replace(p.ParameterName, p.Value.ToString());
}
More Related Contents:
- How can I add user-supplied input to an SQL statement?
- Difference with Parameters.Add and Parameters.AddWithValue
- What ‘length’ parameter should I pass to SqlDataReader.GetBytes()
- how to add new method to TextBox Class [closed]
- Determine if a number can be made with prepicked numbers and times
- MetadataException: Unable to load the specified metadata resource
- Reading PDF content with itextsharp dll in VB.NET or C#
- Can you get the column names from a SqlDataReader?
- Is it necessary to manually close and dispose of SqlDataReader?
- When using Trusted_Connection=true and SQL Server authentication, will this affect performance?
- How to execute an SSIS package from .NET?
- Should I store my images in the database or folders? [duplicate]
- How to create a DataTable in C# and how to add rows?
- Accessing Office Word object model through asp.net results in “failed due to the following error: 80070005 Access is denied.”
- ado.net Closing Connection when using “using” statement
- Winforms: Application.Exit vs Environment.Exit vs Form.Close
- Launching a process in user’s session from a service
- How to pass a table-value parameter
- The State of Linkers for .NET apps (aka “Please Sir, May I have a Linker” 2009 edition)
- How to keep single SQL Server connection instance open for multiple request in C#?
- Fill an array (or arraylist) from SqlDataReader
- How to use SqlCommand to CREATE DATABASE with parameterized db name?
- ExecuteNonQuery returning -1 when using sql COUNT despite the query string
- Can a PictureBox show animated GIF in Windows Application?
- What is the C# version of VB.NET’s InputBox?
- How do I create a delegate for a .NET property?
- How do I connect to a SQL database from C#?
- Select distinct rows from datatable in Linq
- How can I Pass a Table Name to SqlCommand?
- Are there any OK image recognition libraries for .NET?