How to check if SQLDataReader has no rows

后端 未结 4 724
佛祖请我去吃肉
佛祖请我去吃肉 2020-12-10 23:51

I am trying to figure out how to check if my SqlDataReader is null or has no rows (meaning the reservation does not exist) and then display a messagebox. For so

4条回答
  •  心在旅途
    2020-12-11 00:41

    Add this to your code to check:

    sqlCommand cmd = new sqlCommand();
    SqlDataReader dr = cmd.ExecuteReader();
    
    if(dr.HasRows)
    {
        while(dr.Read())
        {
            //code
        }
    }
    

提交回复
热议问题