C#DataTable行索引 [英] C# DataTable row index

查看:829
本文介绍了C#DataTable行索引的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你好,



我是c#的新手。我在做一个项目。我试图通过一个包含大约100,000行的dataTable循环。我使用index作为varibale来访问dataTable的行,如下所示。

Hello,

I am newbie to c#. I working on a project. I am trying to loop thru a dataTable containing about 100,000 rows. I am using index as varibale to access the rows of dataTable like following.

for(int index=0; index< DT.rows.count;index++)
{
    string member ="";
    member = DT.Rows[index]["memberName"];
}



运行32768后显示错误,因为-32768处的位置没有行。我想这是因为DataTable Row索引只接受整数值作为索引,它的值大于32678它显示错误。有谁能告诉我如何摆脱这个???



提前谢谢。



Chowdary 。


After running 32768 it is showing error as There is no row at postion at -32768. I am thinking that this is becuase of DataTable Row index accepts only integer value as index and it's value is more than 32678 it is showing error. Can anybody tell me how to get rid of this???

Thanks in advance.

Chowdary.

推荐答案

嗨这只是因为整数范围,即 int16 数据类型是 -32768到32767 所以之后循环32767次它跳转到负侧并且这个循环重复。

所以为了避免这种使用 long 数据类型或者你也可以简单地使用int。

我建议你写(DT.rows.count - 1)作为索引星从零这也可能导致bug

接受解决方案如果你有解决方案。



谢谢...
hi this is only because range of integer i.e int16 datatype is -32768 to 32767 so after looping 32767 times it jumps into negative side and this cycle repeats.
So to avoid this use long datatype or you can also go with simply int.
i'll suggest you to write (DT.rows.count - 1) as index stars from zero this may also cause bug
accept solution if you have got the solution.

thanks...


使用



Use

foreach(DataRow row in DT.Rows)
{
     string member = row["memberName"];
}


这篇关于C#DataTable行索引的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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