0

Hi, I have problems with passing parameters in a object to string, take a look to my codes:

DataTable dt = new DataTable();
               
                string SQLStr = ""; // sql query
                dt = AccessDb_Cmd.RetrieveData(SQLStr, Access_Db).Tables[0];

                string c1,c2,c3,c4,c5,c6;               
                int i;
                foreach (DataRow row in dt.Rows)
                {
                    i = 0;
                    object array = row.ItemArray;
                 //how to pass at here?
                                  
                }

Datatable dt contains 6 columns, I wants pass the contents in array ( after stored from dt) to c1,c2,c3 to c6 respectively. In VB.net, I can do it as "c=array(i)", but in c#, it cannot write as "array". Anyone got idea?

Edited by leo88: n/a

2
Contributors
2
Replies
3
Views
6 Years
Discussion Span
Last Post by leo88
0

Depends on number of columns.
For example if you have 3 columns you do:

foreach (DataRow row in dt.Rows)
{
    object obj1 = row[0]; //column 1
    object obj2 = row[1]; //column 2
    object obj3 = row[2]; //column 3
}
0

Depends on number of columns.
For example if you have 3 columns you do:

foreach (DataRow row in dt.Rows)
{
    object obj1 = row[0]; //column 1
    object obj2 = row[1]; //column 2
    object obj3 = row[2]; //column 3
}

That is the solution! Thank you very much:)

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.