How can I loop through the rows of a DataGridView one at a time (I have 2 columns), then store those 2 columns in a variable that will be used as a parameter for an sql query?
foreach (DataGridViewRow Datarow in contentTable_grd.Rows)
{
contentValue1 = Datarow.Cells[0].Value.ToString();
contentValue2 = Datarow.Cells[1].Value.ToString();
SqlParameter param4 = new SqlParameter("@contentTableValue1", contentValue1);
SqlParameter param5 = new SqlParameter("@contentTableValue2", contentValue2);
}
I’m getting this error when using the above code:
Object reference not set to an instance of an object.
Found the problem I needed an if statement to prevent empty cells from going through