Paul Clement
5/6/2005 2:43:00 PM
On 5 May 2005 10:11:53 -0700, sunny076@yahoo.com wrote:
¤ Hi,
¤
¤ I am having a puzzling problem with ODBC connection. I am trying to
¤ insert into Access database.I got this error when I run my code "ERROR
¤ [07002] [Microsoft][ODBC Microsoft Access Driver] Too few parameters.
¤ Expected 2." I took the same insert command and used in Access directly
¤ and the insert was successful. I don''t understand why I got the error.
¤
¤ The code I used is below:
¤
¤ OdbcCommand cmd = conn.CreateCommand();
¤ cmd.CommandText = "INSERT INTO [Cust] ([FirstName], [EmpID]) VALUES
¤ (@FirstName, @EmpID)"
¤ string[] mappedValue ={"Sunny", 12};
¤ for(int i =0; i<paramNameList.Length; i++){
¤ OdbcParameter pm = new OdbcParameter(paramNameList[i], odbcType,
¤ colMD.ColumnSize);
¤ cmd.Parameters.Add(pm);
¤ cmd.Parameters[i].Value=mappedValue[i];
¤ }
¤ cmd.ExecuteNonQuery();
¤
Microsoft recommends that you use Jet OLEDB instead of the Microsoft ODBC driver for stability and
support reasons.
I can''t spot any error in the above code, unless the code to add your parameters is not executing.
Paul
~~~~
Microsoft MVP (Visual Basic)