我正在尝试使用此字段将新记录插入表中,但是它给了我“条件表达式中的数据类型不匹配......我已经检查了类型,它总是会失败...
我不知道该字段的大小是否正确,需要帮助吗?
public static void InsertCommand(Veicolo v, string connString)
{
using (OleDbConnection connection = new OleDbConnection(connString))
{
connection.Open();
OleDbCommand cmd = new OleDbCommand
{
CommandText = "INSERT INTO Veicoli VALUES ('@targa', @automoto,'@marca', '@modello', @cilindrata, @potenzakw," +
"@immatricolazione,@usato,@kmzero,@kmpercorsi,'@colore',@prezzo,'@imagepath','@caratteristica');",
Connection=connection
};
cmd.Parameters.Add("@targa",OleDbType.VarChar,255).Value= v.Targa;
cmd.Parameters.Add("@automoto",OleDbType.Boolean,2).Value = (v is Auto);
cmd.Parameters.Add("@marca", OleDbType.VarChar, 255).Value = v.Marca;
cmd.Parameters.Add("@modello", OleDbType.VarChar, 255).Value = v.Modello;
cmd.Parameters.Add("@cilindrata", OleDbType.Integer, 32).Value = v.Cilindrata;
cmd.Parameters.Add("@potenzakw", OleDbType.Double, 32).Value = v.PotenzaKw;
cmd.Parameters.Add("@immatricolazione", OleDbType.DBDate, 32).Value = v.Immatricolazione;
cmd.Parameters.Add("@usato", OleDbType.Boolean, 2).Value = v.IsUsato;
cmd.Parameters.Add("@kmzero", OleDbType.Boolean, 2).Value = v.IsKmZero;
cmd.Parameters.Add("@kmpercorsi", OleDbType.Integer, 32).Value = v.KmPercorsi;
cmd.Parameters.Add("@colore", OleDbType.VarChar, 255).Value = v.Colore;
cmd.Parameters.Add("@prezzo", OleDbType.Double, 32).Value = v.Prezzo;
cmd.Parameters.Add("@imagepath", OleDbType.VarChar, 255 ).Value = v.ImagePath;
string c = (v is Auto ? (v as Auto).NumeroAirBag.ToString() : (v as Moto).MarcaSella);
cmd.Parameters.Add("@caratteristica", OleDbType.VarChar, 255).Value =c;
cmd.Prepare();
cmd.ExecuteNonQuery(); //ERROR data type mismatch in criteria expression
}
}
public static string createTableVeicoliSqlString =
$"CREATE TABLE Veicoli (" +
$"Targa varchar(255) NOT NULL PRIMARY KEY," +
$"AutoMoto boolean," +
$"Marca varchar(255)," +
$"Modello varchar(255)," +
$"Cilindrata int," +
$"PotenzaKw double," +
$"Immatricolazione datetime," +
$"Usato boolean," +
$"KmZero boolean," +
$"KmPercorsi int," +
$"Colore varchar(255)," +
$"Prezzo double," +
$"ImagePath varchar(255)," +
$"Caratteristica varchar(255)" +
$");";
除了您排除的原因外,可能有多种原因: