SqlCommand to T-SQL

前端 未结 2 1850
既然无缘
既然无缘 2021-01-26 17:41

Is there any way how to convert SqlCommand object to actual T-SQL command, which is sent to the SQL Server?

2条回答
  •  轻奢々
    轻奢々 (楼主)
    2021-01-26 18:03

    I was actually thinking about something like this extension (not working well, just idea):

    public static string ToQuery(this SqlCommand command)
    {
      StringBuilder sb = new StringBuilder();
      sb.Append("exec ");
      sb.Append(command.CommandText);
    
      List parameters = new List();
    
      for (int i=0; i 0) sb.Append(string.Join(",", parameters.ToArray()));
    
      return sb.ToString();
    }
    

提交回复
热议问题