把SqlDataReader的数据转换成一个DataTable,而我处理它 [英] Put SqlDataReader data into a DataTable while i process it

查看:863
本文介绍了把SqlDataReader的数据转换成一个DataTable,而我处理它的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想查询数据库,并与结果,我想处理它们。而即时处理它们,其中一些将需要被插入到另一个数据库中。既然不能以开放的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?

解决方案

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.

这篇关于把SqlDataReader的数据转换成一个DataTable,而我处理它的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆