How to handle "0 rows found" error while filling datatable with select query that returns 0 rows.

Member Avatar for stbuchok

Can you elaborate?

Not to mention, this doesn't like a C# question. This sounds like a SQL question.

Try to use the HasRows property in SqlDataReader to check whether there are any rows return from the query.

Yep.

SqlCommand cmd = new SqlCommand(@"query", "connection");
SqlDataReader reader = cmd.ExecuteReader();
if(reader.HasRows)
{
     
}
else
     MessageBox.Show("No rows found.");
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.