I'm relatively new to programming, so be easy!
An unhandled exception of type 'System.ArgumentOutOfRangeException' occurred in mscorlib.dll
Additional information: Index was out of range. Must be non-negative and less than the size of the collection.
How Can i prevent these errors from occurring after iterating through the datagridview. The code does exactly what is needed. The for loop has iterated through all the rows but throws exception when no rows are left. How can i break out when all rows have been converted?
foreach (DataGridViewRow row in dataGridView1.Rows)
{
for (int i = 0; i < dataGridView1.Columns.Count; i++)
{
//String header = gridview_id.Columns[i].HeaderText;
// String cellText = row.Cells[i].Text;
partData.partID = Convert.ToString(dataGridView1.Rows[i].Cells[0].Value);
partData.productName = Convert.ToString(dataGridView1.Rows[i].Cells[1].Value);
partData.partDescription = Convert.ToString(dataGridView1.Rows[i].Cells[2].Value);
partData.unitPrice = Convert.ToString(dataGridView1.Rows[i].Cells[3].Value);
partData.quantity = Convert.ToString(dataGridView1.Rows[i].Cells[4].Value);
partData.partNote = Convert.ToString(dataGridView1.Rows[i].Cells[5].Value);
MessageBox.Show(PerformRequestUpdatePriority("http://dmcalla04.students.qub.ac.uk/import.php?", username, partData.partID, partData.productName, partData.partDescription, partData.unitPrice, partData.quantity, partData.partNote));
Console.WriteLine(username);
}
}
Many Thanks in advance.