D
Dan
I'm building a small C# application which stores some info into an Access
table; this is the 1st time I'm using Access and the OleDb namespace, as
usually I prefer MSDE (SqlClient namespace), and I'm having this problem:
when inserting or updating a record with 2 text fields and 1 integer field
(the primary key is autonumber) using a stored procedure, I get Data type
mismatch in criteria expression: I have checked the documentation and also
created a collection of parameters using the Visual Studio wizard, and it
seems there is no error in my code; nevertheless, it does not work... Here
is a sample:
a dummy table named TDummy has the fields:
ID = autonumber
first = text (50)
last = text (50)
age = integer
The stored procedure for insertion is:
INSERT INTO TDummy([first], [last], age) VALUES ([?], [?], [?]);
The command:
OleDbCommand cmd = new OleDbCommand("[...the name of the stored proc...]");
cmd.Connection = ...the connection...;
cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.Add(new OleDbParameter("first", OleDbType.VarWChar, 50,
"first"));
cmd.Parameters.Add(new OleDbParameter("last", OleDbType.VarWChar, 50,
"last"));
cmd.Parameters.Add(new OleDbParameter("sourceID", OleDbType.Integer, 0,
"age"));
Later I set the three values e.g. cmd.Parameters[0].Value="Donald",
cmd.Parameters[1].Value="Duck", cmd.Parameters[2].Value = 60, and then I
call cmd.ExecuteNonQuery which always rets a data type mismatch. What's
wrong with this code? Thanx!
table; this is the 1st time I'm using Access and the OleDb namespace, as
usually I prefer MSDE (SqlClient namespace), and I'm having this problem:
when inserting or updating a record with 2 text fields and 1 integer field
(the primary key is autonumber) using a stored procedure, I get Data type
mismatch in criteria expression: I have checked the documentation and also
created a collection of parameters using the Visual Studio wizard, and it
seems there is no error in my code; nevertheless, it does not work... Here
is a sample:
a dummy table named TDummy has the fields:
ID = autonumber
first = text (50)
last = text (50)
age = integer
The stored procedure for insertion is:
INSERT INTO TDummy([first], [last], age) VALUES ([?], [?], [?]);
The command:
OleDbCommand cmd = new OleDbCommand("[...the name of the stored proc...]");
cmd.Connection = ...the connection...;
cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.Add(new OleDbParameter("first", OleDbType.VarWChar, 50,
"first"));
cmd.Parameters.Add(new OleDbParameter("last", OleDbType.VarWChar, 50,
"last"));
cmd.Parameters.Add(new OleDbParameter("sourceID", OleDbType.Integer, 0,
"age"));
Later I set the three values e.g. cmd.Parameters[0].Value="Donald",
cmd.Parameters[1].Value="Duck", cmd.Parameters[2].Value = 60, and then I
call cmd.ExecuteNonQuery which always rets a data type mismatch. What's
wrong with this code? Thanx!