问题描述:

In my program I have a datagridview table c_tbl which gets data from a SQL Server and populates the datagridview. I have a for loop running through each row. Now I have a switch statement that should check each row and get the value so I can compare it and add other data in that row.

This is what it looks like

for(int i=0; i<c_tbl.rows.count; i++){

switch("this is where i need the argument that will check the row and column value)

{

case "string value that gets compared"

//add in values to column on same row.

}

}

I originally had something like

switch(c_tbl.Column[0][i])

but it's not working.

网友答案:

You can loop through the DataTable like this:

foreach (DataRow row in c_tbl.Rows)
{
    foreach (DataColumn col in c_tbl.Columns)
    {
        switch (row[col].ToString())
        {
        }
    }
}
相关阅读:
Top