本文介绍了C#MySQL错误“列计数与第1行的值计数不匹配"的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

//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);
command1.Parameters.AddWithValue("@equipamento", comboequipamento.Text);
command1.Parameters.AddWithValue("@situacao", "Em diagnóstico");
command1.Parameters.AddWithValue("@modelo", tbmodelo.Text);
command1.Parameters.AddWithValue("@nr_serie", tbserie.Text);
command1.Parameters.AddWithValue("@avaria", tbavaria.Text);
command1.Parameters.AddWithValue("@estado_equipamento", tbestado.Text);
command1.Parameters.AddWithValue("@data", Convert.ToString(DateTime.Today.ToShortDateString()));
command1.Parameters.AddWithValue("@estado_reparacao", null);
command1.Parameters.AddWithValue("@reincidente", 1);
command1.Parameters.AddWithValue("@id", tbid.Text);


//Executa a Query SQL
command1.ExecuteNonQuery();
reincidentestr = true.ToString();
Atribuir_IDFichaHTML();

能给我些帮助吗?我在执行command1时得到了Column count doesn't match value count at row 1.

Can I get some help please? Im getting Column count doesn't match value count at row 1 when the command1 is executed.

推荐答案

您的查询是:

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)

您的值比values语句中所需的要少,因为您缺少@situacao@modelo之间的逗号:

You have fewer values than you need in the values statement, because you are missing a comma between @situacao and @modelo:

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)

这是另一个示例,其中良好的格式可以防止出现问题.

This is yet another example where good formatting would have prevented a problem.

这篇关于C#MySQL错误“列计数与第1行的值计数不匹配"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-13 07:12