数据读取器到数据表复制Rcore [英] Data Reader to DataTable Copy the Rcore

查看:145
本文介绍了数据读取器到数据表复制Rcore的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何从DataReader传输Datatable中记录的所有内容

当我使用
datatable.load(datareader);

第一条记录丢失了
表示
我的查询给出4条记录数据表只有3条记录缺少第一条记录;

How To Transfer the all Recored in Datatable From DataReader

when i use
datatable.load(datareader);

the first record is missing
means
my query is giving 4 record dataTable Has only 3 record the first record is missing;

推荐答案

有根据的猜测:
您在执行此操作吗?
Without seeing your code, I can only make an educated guess:
Are you doing this:
SqlDataReader reader = cmd.ExecuteReader();
DataTable dt = new DataTable();
if (reader.Read())
    {
    dt.Load(reader);
    }

因为这是问题所在:Read方法从列表中删除了一条记录...


此代码已成功运行,但缺少最高记录"


是的-Read()方法调用将删除第一条记录.不要叫Read.相反,请检查 reader.HasRows [


试试:

Because, if you are, that''s your problem: the Read method removes one of the records from the list...


"this code is run succesfully but top record is missing"


Yes - the Read() method call removes the first record. Don''t call Read. Instead, check reader.HasRows[^]


"but any option to send data into datatable from datareader"


Try:

SqlDataReader reader = cmd.ExecuteReader();
DataTable dt = new DataTable();
if (reader.HasRows)
    {
    dt.Load(reader);
    }


这篇关于数据读取器到数据表复制Rcore的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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