mohamad guntur

mohamad guntur

  • NA
  • 40
  • 40.6k

Increase stocks to other table

Nov 2 2012 5:41 AM
i got error when using this code


My Tables are
===============================
PRODUCT TR_RECEIVE_PRODUCT
>ID_PRODUCT >ID_RECEIVE_PRODUCT
>NAME >ID_PRODUCT
>CURRENT_STOCK >DATE_IN
>STOCK_IN
====================================

=============================================================================
Private Sub btnAdd_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnAdd.Click
        Dim cmd As New SqlCommand


        Dim connectionString As String = "Data Source=.|dbDIR|;Integrated Security=True;Connect Timeout=30;User Instance=True"
        con = New SqlConnection(connectionString)

        If Not con.State = ConnectionState.Open Then
            con.Open()
        End If

        cmd.Connection = con
        Try
            cmd.CommandText = "INSERT INTO TR_RECEIVE_PRODUCT(ID_RECEIVE_PRODUCT, ID_PRODUCT, DATE_IN, STOCK_IN) VALUES ('" & Me.txtID_RECEIVE_PRODUCT.Text & "', '" & Me.cmbID_PRODUCT.SelectedValue & "', '" & _
                                Me.DateTimePicker1.Value.ToString("yyyy-MM-dd") & "', '" & Me.txtSTOCK_IN.Text & "')"

            cmd.ExecuteNonQuery()
        Catch
            MsgBox("ERROR", MsgBoxStyle.Critical, "Error")
        End Try


        cmd.CommandText = "SELECT * FROM PRODUCT WHERE ID_PRODUCT='" & dgvTB.CurrentRow.Cells(1).Value & "'" 
        cmd = New SqlCommand(cmd.CommandText, con)
        cmd.ExecuteReader()
        If cmd.ExecuteReader.Read = True Then
            current_stock = Convert.ToInt32(cmd.ExecuteReader(5).ToString)
            stock_in = Convert.ToInt32(dgvTB.CurrentRow.Cells(3).Value)
            qty = stock_in + current_stock
            con.Close()
            con.Open()
            cmd.CommandText = "UPDATE PRODUCT SET CURRENT_STOCK='" & qty & "' WHERE ID_PRODUCT='" & dgvTB.CurrentRow.Cells(1).Value & "'"
            cmd = New SqlCommand(cmd.CommandText, con)
            cmd.ExecuteNonQuery()
            MsgBox("stock has been updated", MsgBoxStyle.Information)
            con.Close()
        Else
            MsgBox("Error", MsgBoxStyle.OkOnly)
        End If

        Me.GetData()
        Clear()
        con.Close()

===============================


some error include these statement:
cmd.CommandText = "SELECT * FROM PRODUCT WHERE ID_PRODUCT='" & dgvTB.CurrentRow.Cells(1).Value & "'"

 If cmd.ExecuteReader.Read = True Then


well, the record is still recorded, but the stocks on PRODUCT table won't increased :((