1

geting the recipt id from the database

        SQL = "select max(reciptid) as MAXID from recipts where 1"
        Dim CMD2 As New OleDb.OleDbCommand
        CMD2.Connection = MyConnection
        CMD2.Transaction = MyTransaction
        CMD2.CommandText = SQL
        Dim ReciptID As Long = CMD2.ExecuteScalar()
        CMD2.Dispose()

insert the details of the reciept

         Dim I As Integer
        For I = 0 To DataGridView2.Rows.Count - 1
            'get the values first


            Dim Barcode As String = DataGridView2.Rows(I).Cells(0).Value
            Dim ItemBuyPrice As Decimal = DataGridView2.Rows(I).Cells(2).Value
            Dim ItemSellPrice 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 reciptdetails (reciptid, barcode, itemcount, itembuyprice, itemsellprice) values (:0      ,:1       ,:2        ,:3         ,:4        )"
            CMD3.Connection = MyConnection
            CMD3.Transaction = MyTransaction
            CMD3.CommandType = SQL
            CMD3.Parameters.AddWithValue(":0", ReciptID)
            CMD3.Parameters.AddWithValue(":1", Barcode)
            CMD3.Parameters.AddWithValue(":2", ItemCount)
            CMD3.Parameters.AddWithValue(":3", ItemBuyPrice)
            CMD3.Parameters.AddWithValue(":4", ItemSellPrice)

            CMD3.ExecuteNonQuery()
            CMD3.Dispose()

when i run this query at catch running the SQL command i get this error enter image description here

is there anything wrong with the query ?

Ahsan Baloch
  • 47
  • 10

1 Answers1

0

Here's your error:

CMD3.CommandType = SQL

OleDbCommand.CommandType expects a CommandType value, not a String.

You probably meant to write:

CMD3.CommandText = SQL

I strongly recommend to turn on Option Strict, which allows you to catch such errors at compile-time rather than at run-time.

Heinzi
  • 167,459
  • 57
  • 363
  • 519