日期:2014-05-17  浏览次数:20386 次

在应使用条件的上下文(在 'Admin' 附近)中指定了非布尔类型的表达式
DAL层
C# code

using System;
using System.Data;
using System.Text;
using System.Data.SqlClient;
using DBUtility;//Please add references
namespace DAL
{
                  /// <summary>
        ///     根据用户名获取用户ID
        /// </summary>
        public DataSet GetSessonUserID(string UserName)
        {
            StringBuilder strsql = new StringBuilder();
            strsql.Append("select UserID  ");
            strsql.Append("from Accounts_Users ");
           
            if (UserName!="")
            {
                strsql.Append("where " + UserName);
            }
            return SQLHelper.Query(strsql.ToString());
        }
        /// <summary>
        ///     根据用户名获取用户类别ID(RoleID)
        /// </summary>
        public DataSet GetSessionRoleID(string UserName)
        {
            StringBuilder strsql = new StringBuilder();
            strsql.Append("select RoleID ");
            strsql.Append("from Accounts_Users ");
            if (UserName.Trim()!="")
            {
                strsql.Append("where " + UserName);
            }
            return SQLHelper.Query(strsql.ToString());
        }
        /// <summary>
        /// 获得数据列表
        /// </summary>
        public DataSet GetList(string strWhere)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("select UserID,UserName,UserPassWord,TrueName,Sex,Age,BirthDay,Phone,Email,EmployeeID,DepartmentID,UserType ");
            strSql.Append(" FROM Accounts_Users ");
            if (strWhere.Trim() != "")
            {
                strSql.Append(" where " + strWhere);
            }
            return SQLHelper.Query(strSql.ToString());
        }
           



web层
C# code

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using DBUtility;
using Model;
using DAL;
using BLL;
using System.Data;
using System.Data.SqlClient;
using System.Configuration;

public partial class Admin_AddNews : System.Web.UI.UserControl
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (Session["UserName"] == null)
        {
            Response.Write("<script>alert('您还没有登录!')</script>");
            Response.Redirect("/Admin/Login.aspx");
        }
        if (!IsPostBack)
        {
            BindNewsTypeBind();
        }
        
    }
    private void BindNewsTypeBind()
    {
        BLL.Accounts_NewsType bll = new BLL.Accounts_NewsType();

        DataSet ds = bll.GetAllList();
        this.NewsType.DataSource = ds.Tables[0];
        this.NewsType.DataTextField = "NewsType";
        this.NewsType.DataValueField = "NewsTypeID";
        this.NewsType.DataBind();

    }
    protected void NewsType_SelectedIndexChanged(object sender, EventArgs e)
    {
        BLL.Accounts_NewsType bll = new BLL.Accounts_NewsType();
        DataSet ds = bll.GetList(NewsType.SelectedItem.Value);
        if (ds.Tables[0].Rows.Count>0)
        {
            this.NewsType.DataSource = ds;
            this.NewsType.DataTextField = "NewsType";
            this.NewsType.DataValueField = "NewsTypeID";
            this.NewsType.DataBind();
        }
        //string NewsTypeID = NewsType.SelectedValue;
        //BindNewsTypeBind();
    }

    protected void SaveBtn_Click(object sender, EventArgs e)
    {
        BLL.Accounts_Users UsersBll = new BLL.Accounts_Users();
        BLL.Accounts_News bll = new B