简体   繁体   中英

Status of SQL-query

I want to know, if the SQL-query was executed succesful. In C# I execute the query like this:

using (SqlConnection conn = new SqlConnection("<placeholder>"))
{
    conn.Open();
    SqlCommand command = new SqlCommand("SELECT * FROM table", conn);
    SqlDataReader reader = command.ExecuteReader();
    // Get status of query
}

How do I get the status of the query, that is executed successful or maybe with an error?

If ExecuteReader returns then it succeeded. If it doesn't succeed then it will throw an exception. You should be catching the possible exceptions, just as you should for any code that can reasonably an exception. I'm not going to go into that here because that's a subject in itself that you should become familiar with.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM