将数据添加到数据库时出错

时间:2013-05-22 23:54:28

标签: c# mysql

//Query SQL
MySqlCommand command1 = new MySqlCommand("INSERT INTO Equipamento (equipamento, situacao, modelo, nr_serie, avaria, estado_equipamento, data, estado_reparacao, reincidente, ID)" +
"VALUES(@equipamento, @situacao, @modelo, @nr_serie, @avaria, @estado_equipamento, @data, @estado_reparacao, @reincidente, @id)", mConn);
command.Parameters.AddWithValue("@equipamento", comboequipamento.Text);
command.Parameters.AddWithValue("@situacao", "Em diagnóstico");
command.Parameters.AddWithValue("@modelo", tbmodelo.Text);
command.Parameters.AddWithValue("@nr_serie", tbserie.Text);
command.Parameters.AddWithValue("@avaria", tbavaria.Text);
command.Parameters.AddWithValue("@estado_equipamento", tbestado.Text);
command.Parameters.AddWithValue("@data", Convert.ToString(DateTime.Today.ToShortDateString()));
command.Parameters.AddWithValue("@estado_reparacao", null);
command.Parameters.AddWithValue("@reincidente", 0);
command.Parameters.AddWithValue("@id", tbid.Text);

//Executa a Query SQL
command1.ExecuteNonQuery();
Atribuir_IDFicha();

我有这个代码,它一直有效,直到我参数化了:

  

命令执行期间遇到致命错误。

我做错了什么?

1 个答案:

答案 0 :(得分:3)

您的MySqlCommand变量名为command1,但您要将参数添加到command