Click here to Skip to main content
15,890,438 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
C#
Private Sub OK_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnAdd.Click
 
    Dim sqlQRY As String = "SELECT * FROM Products WHERE ProductCode = '" & txtCode.Text & "'"
    Dim cmd As OleDbCommand = New OleDbCommand(sqlQRY, conn)
    Dim rdr As OleDbDataReader = cmd.ExecuteReader
 
    If txtCode.Text = "" Then
        MessageBox.Show("Input a product code!", "Warning!", MessageBoxButtons.OK, MessageBoxIcon.Exclamation)
        txtCode.Text = ""
        txtCode.Focus()
    ElseIf rdr.HasRows Then
        rdr.Read()
 
        Dim intProductID As Integer = rdr("ProductID").ToString
 
        Dim newRow As SalesDataSet.SalesDetailsRow = SalesDataSet.SalesDetails.NewSalesDetailsRow
 
        newRow.SalesID = SalesIDTextBox.Text
        newRow.ProductName = intProductID
        newRow.Qty = 1
        Dim Price As Decimal = rdr("Price")
        newRow.Price = Price
        newRow.Amount = Price
 
        SalesDataSet.SalesDetails.Rows.Add(newRow)
 
        txtCode.Text = ""
        txtCode.Focus()
    Else
        MessageBox.Show("Product not found!", "Warning!", MessageBoxButtons.OK, MessageBoxIcon.Exclamation)
        txtCode.Text = ""
        txtCode.Focus()
    End If
 
    txtTotal.Text = Totals()
 
    Dim vat As Decimal
 
    vat = Val(txtTotal.Text) * 0.12
 
    txtVAT.Text = vat
    Button1.Enabled = True

End Sub


What I have tried:

I tried to to change " newRow.Qty = 1 " to " newRow.Qty += 1 " but not working!

Please help me for this code. Thanks ! :)
Posted
Updated 16-May-16 8:05am
v2
Comments
Maciej Los 16-May-16 12:56pm    
Dim intProductID As Integer = rdr("ProductID").ToString() ???
ionMEMBER 16-May-16 12:59pm    
yes
Maciej Los 16-May-16 13:02pm    
You're trying to cast string to integer. So, what "yes" exactly means?
ionMEMBER 16-May-16 13:06pm    
there are products without productid and this products identified by "tostring"
(example vinegar to vi or bread to br, etc)
ionMEMBER 16-May-16 13:17pm    
Can you help me?

1 solution

i can see where your code is making a read but not a write, you have no code submitting an update to your database in any fashion. you have the reader portion you need the writer portion aka save or update.

you would need something like this code, not perfect though gives you the just of it.

Private Sub save_Click(sender As Object, e As EventArgs) Handles save.Click
        sqlQRY = "Insert into " database" (Qty) values ('" & Qty.Text & "')"     /'or your cell of the datagrid
        Dim cmd As New OleDbCommand(sqlQRY, conn)
 
Share this answer
 
Comments
ionMEMBER 16-May-16 11:10am    
not working

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