我写它包含一个SQL查询代码。 SQL查询工作正常(因为我可以看到数据库的作用)。但是我想显示SQL的消息。当我们运行SQL服务器上此查询,它提供了以下信息,我们理解查询已正确执行:“查询已成功为用户XXX执行” 打印SQL查询消息
下面是我对SQL查询执行的正常工作编写的代码,但我希望能够打印我提到的上述消息。
//SQL Server Connection
string con_str_reenable = "Data Source=SQLSERVER;Initial Catalog=DATABASE;Integrated Security=True";
SqlConnection con_db_reenable = new SqlConnection(con_str_reenable);
//SQL Query:
string reenable_query="The query is pasted here(Exec **** XXX)";
SqlCommand rep_com = new SqlCommand(reenable_query, con_db_reenable);
try
{
SqlDataAdapter sda1 = new SqlDataAdapter();
sda1.SelectCommand = rep_com;
DataTable dbdataset1 = new DataTable();
sda1.Fill(dbdataset1);
}
catch (Exception ex)
{
MessageBox.Show(ex.Message, "Error");
}
}
请帮助我在不更改上面的SQL访问代码的情况下打印消息。
感谢
我想打印SQL查询的实际消息。现在,我使用的String.Format作为一种变通方法,但我想要得到的确切消息。 –
您可以使用[SqlConnection.InfoMessage](https://msdn.microsoft.com/en-us/library/system.data.sqlclient.sqlconnection.infomessage.aspx) –