Click here to Skip to main content
15,890,506 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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...
Posted
Comments
Animesh Datta 5-Oct-13 3:29am    
Hello ,
I think there is no such column name 'id' in your dataset . you just check the proper name and then try it.

thanks
Animesh
ziafahad 5-Oct-13 3:53am    
i checked and id column is there. and I have said in my question that debugging my code, id column value is fetched but is not stored to ids array...
Animesh Datta 5-Oct-13 3:58am    
Hello,
you have to define the array length.
example ...
string[] arr = new string[50];

thanks

you should define length of string array
 
Share this answer
 
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();
}
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900