所以我需要从查询中获取值-在AS TrueOrFalse字段中。 我对应该如何去做感到困惑。
基本思想/措辞:我需要从我的RatingsReviews表中查看BookID中是否存在一个值(将与RequestQuery匹配),然后在UserID中存在一个值(与Session变量匹配/匹配)。
我无权使用.ExecuteScalar方法。
我知道查询应该可以工作,它可以在Access中工作(使用参数值进行一些修改),并且我将“ BookID” RequestQuery和“ UserID” Session Variable用于其他可以正常工作的东西。
这是我的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;
}
答案 0 :(得分:0)
我看到您只填充了SelectCommand属性,因为您从未执行过select命令。您可以使用Select方法执行它并返回结果。
IEnumerable result = _objDS2.Select(new DataSourceSelectArguments());
点击以下链接以正确实施: Google