Array

Posted by Nilschaudhari under C# on 4/9/2008 | Views : 2103 | Status : [Member] | Replies : 2
I use
string[,] arrData = new string[6, 3];

in my application & I have one database table from which i want to fill records in "arrData" please tell me how to add data in arrData.




Responses

Posted by: Raja on: 4/10/2008 [Member] Starter

Up
0
Down
You may use DataTable.Rows.CopyTo(array, index) method

or

you can do following (Loop through the DataTable and fill the aray one by one.

int i = 0;

foreach (DataRow row in DataTable.Rows)
{
arrData[i] = row["myColumn"].ToString()
i++;
}


Here, I am assuming that you will get the Database table records using ADO.NET into DataTable through DataSet.

Regards,
Raja, USA

Nilschaudhari, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Jaydeep on: 10/7/2008 [Member] Starter

Up
0
Down
I want to correct above answer.
int iCount=0;
foreach (DataRow row in DataTable.Rows)
{
arrData [iCount] = row["myColumn"].ToString()
iCount++;
}

Or

foreach (DataRow row in DataTable.Rows)
{
arrData [iCount,0] = row["myColumn1"].ToString()
arrData [iCount,1] = row["myColumn2"].ToString()
arrData [iCount,2] = row["myColumn3"].ToString()
iCount++;
}


Nilschaudhari, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response