Posted on Leave a comment

Tracing Calls to Stored Procedures from C

//where cmd is of type SqlCommand

Console.WriteLine(“”);
Console.WriteLine(cmd.CommandText);
String sep = ” “;
foreach (SqlParameter param in cmd.Parameters)
{
if (param.SqlValue.Equals(“Null”))
{
Console.WriteLine(sep + param.ParameterName + “=” + param.SqlValue);
}
else
{
switch (param.SqlDbType)
{
case SqlDbType.NChar:
case SqlDbType.NVarChar:
case SqlDbType.VarChar:
case SqlDbType.Char:
case SqlDbType.Date:
case SqlDbType.DateTime:
case SqlDbType.DateTime2:
case SqlDbType.SmallDateTime:
case SqlDbType.Text:
Console.WriteLine(sep + param.ParameterName + “='” + param.SqlValue + “‘”);
break;
default:
Console.WriteLine(sep + param.ParameterName + “=” + param.SqlValue);
break;
}
}
sep = “, “;
}
Console.WriteLine(“”);

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.