stock update error some times

  • Thread starter Thread starter muhammadanzar
  • Start date Start date
M

muhammadanzar

Guest
hi

interesting thing in this code is this code is good for 2 products and update its value, on others it create the error which is bold in the code.

,--------------------------------------------------------------------------------------------

Function stockinfo() As Integer
Dim value As Integer
value = 0
Try 'if product sale stock less
If Label34.Text = "Sale Order Management" Then
Dim adapter As New SqlDataAdapter("SELECT Stock FROM dbo.product WHERE ProductCode =" & TextBox9.Text, connection)
Dim table As New DataTable()
adapter.Fill(table)
If Val(table(0)(0) <= 0) Then
MessageBox.Show("Product Out Of Stock", "Read Message Carefully", MessageBoxButtons.OK, MessageBoxIcon.Stop, MessageBoxDefaultButton.Button2)
TextBox9.Clear()
TextBox10.Clear()
TextBox11.Clear()
Return 0

End If
value = table(0)(0) - Val(TextBox11.Text)
Dim command As New SqlCommand("UPDATE dbo.product SET dbo.product.stock=@stock WHERE dbo.product.productcode = " & TextBox9.Text, connection)
command.Parameters.Add("@stock", SqlDbType.Int).Value = value
connection.Open() 'create error the connection was not closed. the connection,s current state is open

command.ExecuteNonQuery()

connection.Close()
End If
Catch ex As Exception
MsgBox(ex.Message)
Finally
End Try
Return value
End Function

'-----------------------------------------------------

'see the image

1400641.jpg


'this image will show the code which is executed for product


when code run on same values it works,it also work on one other value also. it not work the given code

1400646.jpg



MUHAMMAD ANZAR E-mail : muhammadanzar@hotmail.com Mobile # :0092-3215096959

Continue reading...
 
Back
Top