把SqlDataReader的数据转换成一个DataTable,而我处理它而我、转换成、数据、SqlDataReader

2023-09-07 16:55:06 作者:念你成疾.

我想查询数据库,并与结果,我想处理它们。而即时处理它们,其中一些将需要被插入到另一个数据库中。既然不能以开放的SqlDataReader的运行另一个查询(据我所知)。我还想着把数据从SqlDataReader中到一个DataTable,而我处理它。是否有一个内置的方式做到这一点,还是有可以完成同样的想法,另一种解决方案?

解决方案

  SqlDataReader的读卡器= com.ExecuteReader();
数据表DT =新的DataTable();
dt.Load(读卡器);
 

使用的标准设置了休息和拆除的SqlCommand对象,当然。

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?

解决方案 EXCEl中一个很长的行数据,转换成每10列一行

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.