I tried following code but I couldn't find success messages from it.Here commandText can be insert,update,delete or select query and I need dataset if it is a select query else success messages like in sql result output("12 row(s) inserted successfully").I can't use ExecuteScalar or ExecuteNonQuery methods since I need dataset output when select query executed.
public static DataSet ExecuteDataset(string connectionString, CommandType commandType, string commandText, params SqlParameter[] commandParameters)
{
using (SqlConnection cn = new SqlConnection(connectionString))
{
cn.InfoMessage += delegate(object sender, SqlInfoMessageEventArgs e)
{
MessageInfo += "\n" + e.Message;
};
cn.FireInfoMessageEventOnUserErrors = true;
cn.Open();
using (SqlCommand command = new SqlCommand(commandText, cn))
{
using (SqlDataAdapter adapter = new SqlDataAdapter(command))
{
DataSet dt = new DataSet();
adapter.Fill(dt); // Do something with DataTable
return dt;
}
}
}
}