I can insert records into an Access database with this statement:
but if I try to parameterize the statement like this:
I get this error:
Any suggestions?
tia,
flynn
Code:
cmdAdd.CommandText = "INSERT INTO tblTest (Parm1, Parm2, Parm3, Parm4, Parm5, Parm6, Parm7, Parm8) VALUES" & _
"(" & Parm1 & "," & _
Parm2 & "," & _
Parm3 & "," & _
Parm4 & "," & _
Parm5 & "," & _
Parm6 & "," & _
Parm7 & "," & _
Parm8 & ")"
cmdAdd.ExecuteNonQuery()
but if I try to parameterize the statement like this:
Code:
cmdAdd.CommandText = "INSERT INTO tblTest (" & _
"Parm1, Parm2, Parm3, Parm4, Parm5, Parm6, Parm7, Parm8) VALUES (" & _
"@Parm1, @Parm2, @Parm3, @Parm4, @Parm5, @Parm6, @Parm7, @Parm8)"
cmdAdd.Parameters.Add("@Parm1", OdbcType.VarChar, 8).Value = lvItem.Text
cmdAdd.Parameters.Add("@Parm2", OdbcType.VarChar, 50).Value = lvItem.SubItems(1).Text
cmdAdd.Parameters.Add("@Parm3", OdbcType.Date, 10).Value = CDate(lvItem.SubItems(2).Text)
cmdAdd.Parameters.Add("@Parm4", OdbcType.VarChar, 255).Value = lvitem.SubItems(3).Text
cmdAdd.Parameters.Add("@Parm5", OdbcType.VarChar, 255).Value = lvitem.SubItems(4).Text
cmdAdd.Parameters.Add("@Parm6", OdbcType.VarChar, Int32.MaxValue).Value = lvitem.SubItems(5).Text
cmdAdd.Parameters.Add("@Parm7", OdbcType.VarChar, 255).Value = lvitem.SubItems(6).Text
cmdAdd.Parameters.Add("@Parm8", OdbcType.VarChar, 50).Value = lvitem.SubItems(7).Text
cmdAdd.ExecuteNonQuery()
I get this error:
Code:
System.Data.Odbc.OdbcException was caught
ErrorCode=-2146232009
Message="ERROR [07002] [Microsoft][ODBC Microsoft Access Driver] Too few parameters. Expected 8."
Source="odbcjt32.dll"
StackTrace:
at System.Data.Odbc.OdbcConnection.HandleError(OdbcHandle hrHandle, RetCode retcode)
at System.Data.Odbc.OdbcCommand.ExecuteReaderObject(CommandBehavior behavior, String method, Boolean needReader, Object[] methodArguments, SQL_API odbcApiMethod)
at System.Data.Odbc.OdbcCommand.ExecuteReaderObject(CommandBehavior behavior, String method, Boolean needReader)
at System.Data.Odbc.OdbcCommand.ExecuteNonQuery()
at DataParser.Main.btnSaveData_Click(Object sender, EventArgs e) in C:\Visual Studio 2005\Projects\Data\Data1\Main.vb:line 574
Any suggestions?
tia,
flynn