I was trying to update a field called ‘instock'( type is double in database), where the itemcode is a value (type is long integer in access database). But when I try to update them, I get a error which says ‘Invalid index 2 for this oledbparamterCollection with count=2. Can anyone help me please?
strSQL = "UPDATE tblitem set instock = ? where itemcode= ? "
Using cn As New OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + Application.StartupPath + "\\POS.mdb"), _
cmd As New OleDbCommand(strSQL, cn)
cmd.Parameters.Add("?", OleDbType.Double)
cmd.Parameters.Add("?", OleDbType.integer)
cn.Open()
For Each ls As ListViewItem In ListItems.Items
If Not (ls.SubItems(1).Tag(0) = "n") Then
cmd.Parameters(1).Value = (ls.SubItems(1).Tag - ls.SubItems(1).Text)
cmd.Parameters(2).Value = ls.Tag
cmd.ExecuteNonQuery()
End If
Next ls
cn.Close()
End Using
Thanks , + I get this error ‘no default member found for the type double’ while exucating this command:
strSQL = "UPDATE tblitem set instock = ? where itemcode= ? "
Using cn As New OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + Application.StartupPath + "\\POS.mdb"), _
cmd As New OleDbCommand(strSQL, cn)
cmd.Parameters.Add("?", OleDbType.Double)
cmd.Parameters.Add("?", OleDbType.Double)
cn.Open()
For Each ls As ListViewItem In SalesListItems.Items
If Not (ls.SubItems(1).Tag(0) = "n") Then
cmd.Parameters(0).Value = (CDbl(ls.SubItems(1).Tag) + CDbl(ls.SubItems(1).Text))
cmd.Parameters(1).Value = Integer.Parse(ls.Tag)
cmd.ExecuteNonQuery()
End If
Next ls
cn.Close()
End Using
Indices are 0-based in the .NET class library, including ADO.NET1
Parameters(1)means “the 2nd parameter” andParameters(2)means “the 3rd parameter” (which is invalid here).1 This isn’t true for all collections, but it is the most prevalent convention used these days. For instance, collections in the Outlook Object Model, which is COM exposed to .NET, indices are still 1-based ..