我从datagridview和其他变量中获取数据,我想将它保存在我的数据库中,但我得到错误:列数与第1行的值不匹配。 代码:
MySqlCommand comando2 = new MySqlCommand(string.Format("Insert into
producto_vendido (IdProducto_Vendido, IdVenta, IdProducto, Nombre_Producto,
Precio_Unitario, Cantidad_Vendida, Pago_Total) values ("@d0,@d1,@d2,@d3,@d4,@d5,@d6)"), conexion);
comando2.Prepare();
foreach (DataGridViewRow row in dgv1.Rows)
{
if (!row.IsNewRow)
{
comando2.Parameters.AddWithValue("@d0",pSocio.IdProductoVendido);
comando2.Parameters.AddWithValue("@d1",IdVenta)
comando2.Parameters.AddWithValue("@d2", row.Cells[0].Value);
comando2.Parameters.AddWithValue("@d3", row.Cells[1].Value);
comando2.Parameters.AddWithValue("@d4", row.Cells[2].Value);
comando2.Parameters.AddWithValue("@d5", row.Cells[3].Value);
comando2.Parameters.AddWithValue("@d6", row.Cells[4].Value);
comando2.ExecuteNonQuery(); <--- (visual show the error here )
comando2.Parameters.Clear();
}
}