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?

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
}

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:)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.