0
votes

I am trying to insert into an access database. all the fields worked except for the "passwordx" field in which I get data type mismatch in criteria expression.

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.

1
does it matter that you have =mem.password and not =mem.passwordx - Rob Anthony
Difficult to say without knowing the table schema. - Olivier Jacot-Descombes
the password field is set as short text - stav inski
what is the exact type of the column? - Olivier Jacot-Descombes
@Olivier "Short Text" is the column type in Access. - C Perkins

1 Answers

2
votes

Shuffle the last two parameters to match the sequence of your 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.