Hi,
I have an e-commerce website written in asp 1.1,
vb.net and utilising an access database. Within the database I have a ProductID value to identify each product. Within the following sub procedure I want to be able to reference this value as I want to be able to check if there are enough items in stock. The code below uses the cartitemID and quantity as variables. However to reference individual items in the database I surely will need to pass the ProductID value. How should I approach this ?
Code:
Sub dgCart_Update(sender As Object, e As DataGridCommandEventArgs)
Dim intCartitemID As Integer
Dim txtQuantity As TextBox
Dim intQuantity As Integer
'Passes ProductID as sender
'Dim intProductID As Integer ??????
intCartitemID = dgCart.DataKeys(e.Item.ItemIndex)
txtQuantity = e.Item.FindControl("txtQuantity")
intQuantity = txtQuantity.Text
'Define intQuantityInStock and reference to CheckQuantity function
Dim intQuantityInStock As Integer = CheckQuantity(intProductID)
'If statement to check enough quantity in stock
If intQuantityInStock < intQuantity
lblError.Text = "This item is currently low in stock. Please select an alternative</b>"
lblError.Visible = True
Else
Dim strSQL As String = "UPDATE [tblCartItems] SET [intQuantityOrder]=@Quantity WHERE "& _
"intCartitemID = @intCartitemID"
Dim dbCommand As New OleDbCommand(strSQL, dbConnection)
Dim cmd As New OleDbCommand
dbCommand.Parameters.Add("@Quantity", intQuantity)
dbCommand.Parameters.Add("@intCartitemID", intCartitemID)
dbConnection.Open()
dbCommand.ExecuteNonQuery()
dbConnection.Close()
dgCart.EditItemIndex = -1
dgCart.DataSource = DisplayCart()
dgCart.DataBind()
End If
End Sub