简体   繁体   English

尝试从C#插入Access数据库时数据类型不匹配

[英]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.

相关问题 尝试插入Access数据库时条件表达式错误中的数据类型不匹配 - Data type mismatch in criteria expression error when trying to insert into Access database c# 插入数据库数据类型不匹配错误 - c# insert to database data type mismatch error 使用Microsoft Access数据库引擎在Visual c#中评估Access计算字段时,数据类型不匹配 - Data Type Mismatch when evaluating Access Calculated Fields in Visual c# using Microsoft Access Database Engine 将记录从C#保存到Access时“条件表达式中的数据类型不匹配” - “Data type mismatch in criteria expression” when saving record to Access from C# C#“当将数据集的日期添加到数据库时,条件表达式中的数据类型不匹配 - C# "Data type mismatch in criteria expression, when adding date from dataset to database 试图从C#将数据插入到Access数据库中,但是失败了,我也不知道为什么 - Trying to insert data into an access database from C#, but it fails, and I have no idea why C#访问:INSERT SQL语句的条件表达式错误中的数据类型不匹配 - C# Access: Data type mismatch in criteria expression error for INSERT SQL statement 尝试将数据插入SQLite数据库时数据类型不匹配 - Datatype mismatch when trying to insert data into SQLite Database 使用ADO.NET C#从MS Access中删除时,数据类型不匹配的准则表达错误 - data-type-mismatch-in-criteria-expression-error when delete from MS Access with ADO.NET C# ASP C# 更新访问数据库中的条件表达式中的数据类型不匹配 - Data type mismatch in criteria expression in ASP C# Update Access Database
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM