Click here to Skip to main content
15,881,248 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
i am getting an error message that states "parameter :1 has no default value "

What I have tried:

VB
Dim i As Integer
  
      For i = 0 To DataGridView2.Rows.Count - 1
          Dim barcode As String = DataGridView2.Rows(i).Cells(1).Value
          Dim buyprice As Decimal = DataGridView2.Rows(i).Cells(2).Value
          Dim saleprice As Decimal = DataGridView2.Rows(i).Cells(3).Value
          Dim itemcount As Integer = DataGridView2.Rows(i).Cells(4).Value
          Dim cmd3 As New OleDb.OleDbCommand
          sql = "insert into recieptdetails" & _
              "(recieptID,barcode,itemcount,buyprice,saleprice)" & _
              "values" & _
              "( :0      ,:1     ,:2      ,:3     ,:4     )"
          cmd3.Connection = myconnection
          cmd3.Transaction = mytransaction
          cmd3.CommandText = sql
          cmd3.Parameters.AddWithValue(":0", recieptID)
          cmd3.Parameters.AddWithValue(":1", barcode)
          cmd3.Parameters.AddWithValue(":2", itemcount)
          cmd3.Parameters.AddWithValue(":3", buyprice)
          cmd3.Parameters.AddWithValue(":4", saleprice)
          cmd3.ExecuteNonQuery()
          cmd3.Dispose()
      Next
      
      mytransaction.Commit()
      mytransaction.Dispose()
      myconnection.Dispose()
      DataGridView2.Rows.Clear()

    Catch ex As Exception

        MsgBox(ex.Message)

        If mytransaction IsNot Nothing Then
            mytransaction.Rollback()
        End If

        If myconnection IsNot Nothing Then
            If myconnection.State = ConnectionState.Open Then
                myconnection.Close()
            End If
        End If
    End Try

End Sub
Posted
Updated 7-Dec-16 23:05pm
v2
Comments
F-ES Sitecore 8-Dec-16 5:46am    
Reading data from a grid view cell is a bad idea as it is likely your data is going to have extra things added by .net such as line breaks etc. Instead you should read from the data the grid is bound to as that is the raw data you need.

1 solution

You have not declared or initialised recieptID before trying to use it.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900