-1
the code is as follows, I am making an Insert from values of a data grid view
foreach (DataGridViewRow row in dgvCON.Rows)
{
MySqlCommand cmd = new MySqlCommand();
cmd = conectabanco.CreateCommand();
if (row.IsNewRow) continue;
cmd.Parameters.AddWithValue("@IdProd", row.Cells["Id"].Value);
cmd.Parameters.AddWithValue("@QtdProd", row.Cells["Quantidade"].Value);
cmd.Parameters.AddWithValue("@NomeProd", row.Cells["Nome"].Value);
cmd.Parameters.AddWithValue("@PrecoUnitProd", row.Cells["R$ Unidade"].Value);
cmd.Parameters.AddWithValue("@TotalListaConsu", row.Cells["Total"].Value);
cmd.CommandText = "INSERT INTO listaconsumo(IdCon, IdProd, QtdProd, PrecoUnitProd, " +
"totalListaConsu)VALUES("+idconsumo+", @IdProd, @QtdProd, @NomeProd, @PrecoUnitProd, @totalListaConsu)";
cmd.ExecuteNonQuery();
}
The problem is that when running Sql, it sends the "@Idprod" value itself instead of being replaced by the value of datagridview
Please [Edit] the question and add the code directly into the body of it. [en.so] has native support for the codes, so avoid posting them as an image. Do the [tour] to learn the basics of how the site works.
– Woss
Thank you, already changed!
– Fabricio Malta
why not put this "+idconsumo+" as parameter too ?
– Rovann Linhalis