两个表:
购物车(CARTID,用户ID,DateCreated,ProductID,productName,sige,价格,价格,数量,数量,小计,工作时间(
(products (productid,name,sdescription,价格,大小,图像,缩略图,重量,ldescription,ldescription,cott,cattoryId,hourswork(
>我要做的事情:根据SELECT语句选择的类别的所有显示两个按钮之一。
类别ID范围为1-7。如果选定的任何类别匹配" 1" 2"或" 7",则应显示'创建预订'按钮,否则应显示'交货选项'按钮。
Protected Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs)
'Display the correct button:
Dim conn As SqlConnection = New SqlConnection(ConnectionString)
Dim cmd As SqlCommand = New SqlCommand
cmd.CommandText = "SELECT products.CategoryID FROM Products INNER JOIN Cart on products.ProductID = cart.ProductID WHERE ([UserID] = @UserID) AND ([DateCreated] = CONVERT(date, GETDATE()))"
Dim UserID As SqlParameter = New SqlParameter("@UserID", SqlDbType.NVarChar, 128)
UserID.Value = "249f38b8-e745-44f4-8d78-806b0e5e7e0e"
cmd.Parameters.Add(UserID)
cmd.Connection = conn
conn.Open()
cmd.ExecuteNonQuery()
Dim reader As SqlDataReader = cmd.ExecuteReader
Dim CategoryID As Integer
While reader.Read()
'CategoryID = reader.GetValue(0)
CategoryID = CType(reader("CategoryID"), Integer)
End While
conn.Close()
lblTest.Text = CategoryID
If CategoryID = "1" Or "2" Or "7" Then
btnCreateBooking.Visible = True
Else
btnDeliveryOptions.Visible = True
End If
End Sub
但是,sqldatareader在标签/变量中生产的 last 产品的类别ID是唯一的,。
在此处找到答案:https://forums.asp.net/t/1401666.aspx?c datareader returning multiple mmultiple mmultiple ass ass ass ass ass label quequestion quequestion quequest/p>
If reader.HasRows Then
While reader.Read()
lblTest.Text = (lblTest.Text _
+ (reader("CategoryID").ToString + "<br>"))
End While
conn.Close()
End If
并将我的if语句更正为:
If lblTest.Text.Contains("1") Or lblTest.Text.Contains("2") Or lblTest.Text.Contains("7") Then
btnCreateBooking.Visible = True
Else
btnDeliveryOptions.Visible = True
End If