Difference between SqlDataReader.Read and SqlDataReader.NextResult

后端 未结 2 1974
花落未央
花落未央 2020-12-09 14:52

What is the main difference between these two methods? On the msdn website it is explained like below but I don\'t understand it.

Read Advances the Sql

2条回答
  •  旧时难觅i
    2020-12-09 15:40

    Not strictly an answer to this question but if you use the DataTable.Load method to consume data from the reader rather than Reader.Read note that after the Load method has completed, the reader is now placed at the start of the next result set so you should not call the NextResult method otherwise you will skip the next resultset.

    A simple loop on Reader.HasRows around a DataTable.Load call is all that you need to process potential multiple resultsets in this scenario.

提交回复
热议问题