//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();
我有这段代码,在我对其进行参数化之前它一直有效:
Fatal error encountered during command execution.
我做错了什么?
最佳答案
您的 MySqlCommand
变量称为 command1
,但您正在将参数添加到 command
。
关于c# - 向数据库添加数据时出错,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16703469/