• 首页 首页 icon
  • 工具库 工具库 icon
    • IP查询 IP查询 icon
  • 内容库 内容库 icon
    • 快讯库 快讯库 icon
    • 精品库 精品库 icon
    • 问答库 问答库 icon
  • 更多 更多 icon
    • 服务条款 服务条款 icon

数据读取器到数据表复制Rcore

用户头像
it1352
帮助1

问题说明

如何从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;

正确答案

#1
有根据的猜测:
您在执行此操作吗?
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);
    }

这篇好文章是转载于:学新通技术网

  • 版权申明: 本站部分内容来自互联网,仅供学习及演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,请提供相关证据及您的身份证明,我们将在收到邮件后48小时内删除。
  • 本站站名: 学新通技术网
  • 本文地址: /reply/detail/tanhcfhagh
系列文章
更多 icon
同类精品
更多 icon
继续加载