Put SqlDataReader data into a DataTable while i process it

一个人想着一个人 提交于 2019-12-13 04:19:09

问题


I want to query a database and with the results, i want to process them. While im processing them, some of them will need to be inserted into another database. Since i cannot run another query with an open SqlDataReader (that i know of). I was thinking about putting the data from the SqlDataReader into a DataTable while i process it. Is there a built in way to do this or is there another solution that can accomplish the same idea?


回答1:


SqlDataReader reader = com.ExecuteReader();
DataTable dt = new DataTable();
dt.Load(reader);

With the rest of the standard set-up and tear-down of SqlCommand objects, of course.




回答2:


The easiest way would be to use a DataAdapter to fill a datatable. Then process the data and update the database. Filling a dataset does not tie up the connection once the fill is complete.



来源:https://stackoverflow.com/questions/9534718/put-sqldatareader-data-into-a-datatable-while-i-process-it

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!