Should I call SqlDataReader.HasRows if I am calling SqlReader.Read

后端 未结 5 1872
一向
一向 2020-12-10 01:46

Trying to see if it is beneficial to add an if (dr.HasRows) before the while (dr.read()) function. I mean, technically if it doesn\'t have rows it

5条回答
  •  被撕碎了的回忆
    2020-12-10 02:12

    It's not mandatory to check if the DataReader has rows (dr.HasRows). The Read() method will return true if there is more data to read and false if there's no more data, thus breaking the while-loop.

提交回复
热议问题