我的代码有问题,如果它高于或低于数据库中的值,如何检查文本框中的值? 这是我的代码:
Public Sub additem()
Dim str As String
Dim cmd As New MySqlCommand
Dim dr As MySqlDataReader
Try
str = "select * from tbl_items where ItemName = '" & TextBox1.Text & "'"
con.Open()
With cmd
.CommandText = str
.Connection = con
End With
dr = cmd.ExecuteReader
While dr.Read
Dim qty As String = dr("quantity")
Dim ctgy1 As String = dr("category")
If quantity.Text = "" Then
MsgBox("Please Add Quantity or Number of Order(s)!", MsgBoxStyle.Information, "Quantity")
ElseIf ctgy1 IsNot "Dish" Then
If TextBox1.Text > qty Then
MsgBox("Insufficient Stock!", MsgBoxStyle.Information, "Quantity")
Else
Dim price As Decimal = dr("Price")
Dim itemcode As String = dr("ItemName")
Dim ctgy As String = dr("category")
Dim desc As String = dr("description")
totalprice = Val(quantity.Text) * price
CashRegister.BunifuCustomDataGrid2.Rows.Add(itemcode, price, quantity.Text, totalprice, ctgy, desc)
CashRegister.BunifuCustomDataGrid2.Columns("category").Visible = False
con.Close()
UpdateDecreaseQuantity()
loadtables()
dr.Close()
Me.Close()
End If
Else
Dim price As Decimal = dr("Price")
Dim itemcode As String = dr("ItemName")
Dim ctgy As String = dr("category")
Dim desc As String = dr("description")
totalprice = Val(quantity.Text) * price
CashRegister.BunifuCustomDataGrid2.Rows.Add(itemcode, price, quantity.Text, totalprice, ctgy, desc)
CashRegister.BunifuCustomDataGrid2.Columns("category").Visible = False
con.Close()
UpdateDecreaseQuantity()
loadtables()
dr.Close()
Me.Close()
End If
End While
Catch ex As Exception
Finally
End Try
End Sub
我要发生的是,如果类别不等于Dish或Dessert,它将检查文本框中输入的数量并与数据库中的数量进行比较。有人可以帮我吗?谢谢!