How To Put Data In 2D Array from Dataset Using Loop C#?
i am trying to put data in a 2d array but getting error it add value to 0,0 position then 1,0 position and so on please make it correct
int count = output.Tables[0].Rows.Count;
string[,] terms = new string[count,2];
for (int runs =开发者_JAVA百科 0; runs < count; runs++)
{
terms[0,runs] =output.Tables[0].Rows[runs][0].ToString();
terms[0,runs] =output.Tables[0].Rows[runs][2].ToString();
}
Hopes for your help..
Maybe this should work...
int count = output.Tables[0].Rows.Count;
string[,] terms = new string[count,2];
for (int runs = 0; runs < count; runs++)
{
terms[runs,0] =output.Tables[0].Rows[runs][0].ToString();
terms[runs,1] =output.Tables[0].Rows[runs][2].ToString();
}
you have defined a 2d array of n rows and 2 columns, but in your for you are looping trought the columns
terms[0,runs]
so you get an index error....
terms[runs,0] =output.Tables[0].Rows[runs][0].ToString();
terms[runs,1] =output.Tables[0].Rows[runs][2].ToString();
精彩评论