P.S. Using the technique above you can write a library routine that will even create the SQL statement, and you could simply pass it a reference to any DataGridView and the name of the table into which to sert the data, and never (hardly ever) write an INSERT statement again:
String query = "INSERT INTO test(itemcode,description,quantity,unit) VALUES (itemcode,description,quantity,unit)";
Won't work. C# isn't going to magically convert the variable names in th VALUES clause to the appropriate things.
Best approach would be to make the list in the VALUES clause use parameters.
"INSERT INTO test(itemcode,description,quantity,unit) VALUES ( @itemcode,@description,@quantity,@unit)"
//What is a MySqlCommand? System.Data.SqlCommand is a sealed class, so you can't derive from it...
MySqlCommand command = new MySqlCommand(query, connection);
command.Parameters.Add( new SqlParameter("@itemcode",itemcode);
... the rest, in order...
I would suppose that one other likely cause is that your MySqlCommand Class is flawed, and the constructor
1) Check if row.Cells[X].Value is null or DBnull before converting or ToString()ing them
2) Catch also (Exception ex) and System.Diagnostics.Debug.WriteLine("Error! Source: ", ex.Source + ", Message: " + ex.Message); to see what happened. You can also do this: