【发布时间】:2019-04-06 05:29:50
【问题描述】:
所以我需要从查询中获取值 - 在 AS TrueOrFalse 字段中。 我很困惑我应该如何去做。
在基本思想/措辞中:我需要查看 BookID 中是否存在一个值(与 RequestQuery 匹配),然后从我的 RatingsReviews 表中查看 UserID 中是否存在一个值(匹配/来自会话变量)。
我无权访问 .ExecuteScalar 方法。
我知道查询应该可以工作,它可以在 Access 中工作(稍作修改以使用参数值),并且我正在使用“BookID”RequestQuery 和“UserID”会话变量用于其他按预期工作的事情。
这是我的 WebPageName.aspx.cs 文件中的内容:
SqlDataSource objDS2 = new SqlDataSource();
objDS2.ProviderName = System.Configuration.ConfigurationManager.ConnectionStrings["ConnectionString"].ProviderName;
objDS2.ConnectionString = System.Configuration.ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString;
//Puts the Amount of times that the Session User ID (who's logged in) appears with the Requested Query String of the Book ID
objDS2.SelectCommand = "SELECT COUNT (*) AS TrueOrFalse FROM [RatingsReviews] WHERE ([UserID]" + Session["UserID"].ToString() + " AND [BookID] =" + Request.QueryString["id"].ToString() + ")";
//Get Value from the TrueOrFalse Field from the QUERY somehow
//IF the The value in TrueOrFalse Field is 0,
// then allow and show the Panel, else hide panel - so they cannot enter a review
// if (TrueOrFalse == 0/false)
// {
//is someone logged in?
if (Session["UserID"] != null)
{
//if someone is logged in, and they are visiting
if (Session["UserID"].ToString().Equals(Request.QueryString["id"]))
{
PanelUserRating.Visible = true;
}
else
{
PanelUserRating.Visible = false;
}
【问题讨论】:
标签: c# sql asp.net .net ms-access