[英]data type mismatch when trying to insert into an Access database from C#
I am trying to insert into an access database. 我正在尝试插入Access数据库中。 all the fields worked except for the "passwordx" field in which I get data type mismatch in criteria expression.
除“ passwordx”字段外,其他所有字段均起作用,在该字段中,条件表达式中的数据类型不匹配。
string commandSql = "INSERT INTO Members ( lastName, firstName, id, dob, phone, areaCodeNo, adress, cityNo, zipCode, email, active,passwordx) VALUES ( @lastName, @firstName, @id, @dob, @phone, @areaCodeNo, @adress, @cityNo, @zipCode, @email, @active,@passwordx); ";
OleDbCommand command = new OleDbCommand(commandSql, connection);
command.Parameters.Add("@lastName", OleDbType.VarChar, 100).Value = mem.lastName;
command.Parameters.Add("@firstName", OleDbType.VarChar, 100).Value = mem.firstName;
command.Parameters.Add("@id", OleDbType.VarChar, 100).Value = mem.id;
command.Parameters.Add("@dob", OleDbType.VarChar, 100).Value = mem.dob;
command.Parameters.Add("@phone", OleDbType.VarChar, 100).Value = mem.phone;
command.Parameters.Add("@areaCodeNo", OleDbType.Integer, 100).Value = mem.areaCodeNo;
command.Parameters.Add("@adress", OleDbType.VarChar, 100).Value = mem.adress;
command.Parameters.Add("@cityNo", OleDbType.Integer, 100).Value = mem.cityNo;
command.Parameters.Add("@zipCode", OleDbType.VarChar, 100).Value = mem.zipCode;
command.Parameters.Add("@email", OleDbType.VarChar, 100).Value = mem.email;
command.Parameters.Add("@passwordx", OleDbType.VarChar, 100).Value = mem.password;
command.Parameters.Add("@active", OleDbType.Boolean, 100).Value = mem.active;
connection.Open();
affectedRows = command.ExecuteNonQuery();
connection.Close();
thanks for the help. 谢谢您的帮助。
Shuffle the last two parameters to match the sequence of your SQL: 调整最后两个参数以匹配SQL的顺序:
command.Parameters.Add("@active", OleDbType.Boolean, 100).Value = mem.active;
command.Parameters.Add("@passwordx", OleDbType.VarChar, 100).Value = mem.password;
And a Boolean doesn't have a length. 而且布尔值没有长度。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.