将数据集中每行的列值存储到string []中 [英] storing column value of each row in dataset into string[ ]

查看:76
本文介绍了将数据集中每行的列值存储到string []中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,

我有一个数据集,其中一个表有39行。现在我想将我的id列值的值存储在一个单独的数组中,如string [] id。

i定义了我的数组:

string [] ids = null ;



和我使用此行来存储此数组中的值:

for(int i = 0; i< mydataset.Tables [0] .Rows.Count; i ++)

{

ids [i] = mydataset.Tables [0] .Rows [i] [id]。ToString ();

}



问题是提取了id列值但未存储在ids数组中。它只是抛出一个异常,比如Object引用没有将实例设置为对象的实例。

但是当我使用调试模式来检查我的代码时,我的id列值被提取但是没有存储在ids数组中。

任何人都可以帮忙吗?我错过了什么?

谢谢...

hello everyone,
i have a dataset with one table having 39 rows. now i wanna store the value of my id column value in a separate array like string[] ids.
i have define my array like this:
string[] ids = null;

and i m using this line to store values in this array:
for ( int i = 0; i < mydataset.Tables[0].Rows.Count; i++)
{
ids[i] = mydataset.Tables[0].Rows[i]["id"].ToString();
}

The Problem is that id column value is fetched but is not stored in ids array. it just throw an exception like Object reference not set an instance to an instance of object.
but when i use debug mode to inspect my code, my "id" column value is being fetched but is not stored in ids array.
can anyone help?? what I m missing??
thanks...

推荐答案

你应该定义字符串数组的长度
you should define length of string array


你应该定义字符串的长度



string [] ids = null;





ids =新字符串[mydataset.Tables [0] .Rows.Count];





for(int i = 0; i< mydataset.Tables [0] .Rows.Count; i ++)

{

ids [i] = mydataset.Tables [0] .Rows [i] [id]。ToString();

}
you should define the length of string

string[] ids = null;


ids=new string[mydataset.Tables[0].Rows.Count];


for ( int i = 0; i < mydataset.Tables[0].Rows.Count; i++)
{
ids[i] = mydataset.Tables[0].Rows[i]["id"].ToString();
}


这篇关于将数据集中每行的列值存储到string []中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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