Tuesday, September 25, 2012

c# display SqlCommand statement

      public static string cmdToString(SqlCommand cmd)
      {
         var c = " ";
         var s = cmd.CommandText;
         for (int i = 0; i < cmd.Parameters.Count; i++)
         {
            s += c + cmd.Parameters[i].ParameterName;
            s += " = " + cmd.Parameters[i].Value;
            c = ", ";
         }
         return (s);
      }