我正在尝试插入访问数据库。所有字段都有效,但“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();
感谢您的帮助。
答案 0 :(得分:2)
随机播放最后两个参数以匹配SQL的序列:
command.Parameters.Add("@active", OleDbType.Boolean, 100).Value = mem.active;
command.Parameters.Add("@passwordx", OleDbType.VarChar, 100).Value = mem.password;
布尔没有长度。