我有这个错误。
MySql.Data.MySqlClient.MySqlException:“字段”中的“未知列”值 清单” (“值”属于“类别”)
查询必须添加name_product,价格,类别,但类别无法检测到它。
创建连接
public MySqlConnection getConnection()
{
MySqlConnection conn = new MySqlConnection();
try
{
conn.ConnectionString = getStringConnexio();
return conn;
}
catch
{
MessageBox.Show("Error en la connexió a la base de dades: "
+ servidor + ":" + nameBd);
}
return null;
}
public void ExecutaSql(String sql, MySqlConnection conn)
{
//run the query
MySqlCommand mc = new MySqlCommand(sql, conn);
conn.Open();
mc.ExecuteNonQuery();
}
public void INSERTBD()
{
BaseDades product = new BaseDades();
String sql;
sql = "INSERT INTO enter code hereProductes (nom_producte, preu, categoria) " +
"VALUES ('" + this.nom_producte + "','" +this.preu + "'," + this.categoria + ");";
product.ExecutaSql(sql, product.getConnection());
}