Barcode and adding a row in datagridview

Claude Larocque 666 Reputation points
2021-09-15T19:25:04.52+00:00

Why when I scan barcode with my USB scanner the first barcode generate an unwanted row in my datagridview, but the second scan generate the right product.

I attach a pdf files for this challenging question.

a) I have a form named FrmBilling on which a combobox named BarcodesCBX received the scan for my USB scanner.
b) The possible barcodes are all into this field as you will see on my pdf files.
c) I take my scanner and scan any barcode, the row is added to my datagridview named OrderLinesDGV but that row shows the products information belonging to the first barcode in that combobox, then, if I scan the same barcode a second time I get the right product.

So everytime I scan a product, my application send the product information of the first barcode in the list, I scan the same barcode again and then the right product information is added in my datagridview.

I know someone must have encounter a similar behavior, I hope :)

Claude from Quebec, Canada
My first language being French please forgive the mistakes I do...132437-question-for-barcode-scans.pdf

VB
VB
An object-oriented programming language developed by Microsoft that is implemented on the .NET Framework. Previously known as Visual Basic .NET.
2,569 questions
{count} votes

Accepted answer
  1. Claude Larocque 666 Reputation points
    2021-09-20T10:40:05.967+00:00

    Thanks for helping me and in return I am posting the solution if somebody like me is looking to make the barcode works (Retrieve product information, update SQL database and the order lines in the datagridview)

    Hope that help
    Claude

        Private Sub BarcodeTB_TextChanged(sender As Object, e As EventArgs) Handles BarcodeTB.TextChanged
            Me.UpdateDGV.Select()
            Me.BarcodeTextTB.Select()
        End Sub
    
        Private Sub BarcodeTextTB_KeyDown(sender As Object, e As KeyEventArgs) Handles BarcodeTextTB.KeyDown
            If e.KeyValue = Keys.Enter Then
                LblBarcode.Text = BarcodeTextTB.Text
                BarcodeTextTB.Clear()
            End If
        End Sub
    
        Private Sub LblBarcode_TextChanged(sender As Object, e As EventArgs) Handles LblBarcode.TextChanged
            BarcodeTB.Text = LblBarcode.Text
        End Sub
    
        Private Sub UpdateDGV_Enter(sender As Object, e As EventArgs) Handles UpdateDGV.Enter
            UpdateOrderLinesDGVWithBarcode()
        End Sub
    
    
        Private Sub UpdateOrderLinesDGVWithBarcode()
            Try
                'CLEAR EXISTING RECORD
                If SQL.DBDS IsNot Nothing Then
                    SQL.DBDS.Clear()
                End If
                Me.QtyTB.Text = 1
                SQL.RunQuery("SELECT * FROM Warehouse.ProductsBarcodesEAN13 Where BarcodeEAN13 = '" & BarcodeTB.Text & "' ")
                If SQL.DBDS.Tables(0).Rows(0).Item(0) >= 1 Then
                    Me.InvoicedQuantityTB.Text = 0
                    Me.BackOrderYesNoCB.Checked = False
                    Me.BackorderQuantityTB.Text = 0
                    Me.UnitPriceTB.Text = SQL.DBDS.Tables(0).Rows(0).Item("SellingPrice1")
                    Me.ExtendedPriceTB.Text = QtyTB.Text * UnitPriceTB.Text
                    Me.DiscountRateTB.Text = SQL.DBDS.Tables(0).Rows(0).Item("DiscountRate")
                    Me.DiscountAmountTB.Text = Math.Round(QtyTB.Text * UnitPriceTB.Text) * DiscountRateTB.Text / 100
                    Me.LineTotalTB.Text = QtyTB.Text * UnitPriceTB.Text - DiscountAmountTB.Text
                    Me.DeliveryDateExpectedTB.Text = Now()
                    SQL.AddParam("@OrderNo", Me.OrderNoSelectedTB.Text)
                    SQL.AddParam("@ProductID", SQL.DBDS.Tables(0).Rows(0).Item("ProductID"))
                    SQL.AddParam("@ProductName", SQL.DBDS.Tables(0).Rows(0).Item("ProductName"))
                    SQL.AddParam("@Quantity", QtyTB.Text)
                    SQL.AddParam("@UnitPrice", SQL.DBDS.Tables(0).Rows(0).Item("SellingPrice1"))
                    SQL.AddParam("@ExtendedPrice", Me.QtyTB.Text * Me.UnitPriceTB.Text)
                    SQL.AddParam("@DiscountRate", SQL.DBDS.Tables(0).Rows(0).Item("DiscountRate"))
                    SQL.AddParam("@DiscountAmount", Me.DiscountAmountTB.Text)
                    SQL.AddParam("@InvoicedQuantity", Me.InvoicedQuantityTB.Text)
                    SQL.AddParam("@BackOrderYesNo", Me.BackOrderYesNoCB.Checked)
                    SQL.AddParam("@BackorderQuantity", Me.BackorderQuantityTB.Text)
                    SQL.AddParam("@LineTotal", Me.QtyTB.Text * Me.UnitPriceTB.Text - DiscountAmountTB.Text)
                    SQL.AddParam("@DeliveryDate", Me.DeliveryDateExpectedTB.Text)
                    SQL.ExecQuery("INSERT INTO Sales.OrderLines(OrderNo,ProductID,ProductName,Quantity,UnitPrice,ExtendedPrice,DiscountRate,DiscountAmount,InvoicedQuantity,BackOrderYesNo, " &
                                  "BackOrderQuantity,LineTotal,DeliveryDate) " &
                                  "VALUES (@OrderNo,@ProductID,@ProductName,@Quantity,@UnitPrice,@ExtendedPrice,@DiscountRate,@DiscountAmount,@InvoicedQuantity,@BackOrderYesNo, " &
                                  "@BackorderQuantity,@LineTotal,@DeliveryDate) ", True)
                    RecordsCounted()
                        Me.QtyTB.Text = 1
    
                        'Scroll to the last row.
                        Me.OrderLinesDGV.FirstDisplayedScrollingRowIndex = Me.OrderLinesDGV.RowCount - 1
                        Me.OrderLineIDTB.Text = Me.OrderLinesDGV.RowCount
                        'Select the last row.
                        Me.OrderLinesDGV.Rows(Me.OrderLinesDGV.RowCount - 1).Selected = True
                    End If
                If SQL.HasException(True) Then Exit Sub
            Catch ex As Exception
                MsgBox(ex.Message)
                System.IO.File.AppendAllText("C:\ACRegister\Documents\log.txt", ex.ToString & vbNewLine & vbNewLine)
            End Try
        End Sub
    
    1 person found this answer helpful.

1 additional answer

Sort by: Most helpful
  1. Claude Larocque 666 Reputation points
    2021-09-17T10:46:37.17+00:00

    Sure, the scanner is an Eclipse ES-250A, and I have to mentioned here that when I scan into a notepad or any other software like Excel, Access or Word, everything works fine. Below I scanned 4 articles in notepad

    6819716
    18163780036
    16716990036
    062338929613

    My problem is not the scanner but here are the specifications and the user manual links:

    This the specification for the Eclipse ES-250A
    https://www.eclipse-pos.com/downloads/fiches/es250a-eng.jpg

    This is the barcode scanner user manual for the Eclipse ES-250A
    https://www.eclipse-pos.com/downloads/drivers/Eclipse_ES-250A_v6.6.2.pdf

    I think my problem is easier then the barcode scanner, for example, if I scan any barcode the first time, it works fine but in my BarcodeCBX, the code stays in there, if I manually remove the data into the BarcodeCBX.text then I can scan another one and it works fine.

    So my problem is how to empty completely my combobox after the scan, I tried the SendKeys.Send("{BACKSPACE}") it didn't work, so I am trying other solution, if you have any, please help me!

    Claude

    0 comments No comments