int userid = Convert.ToInt32(new DBoperate().ExecuteScalar("select Employeeid from Employee where username=" + Session["UserName"]));
int userid=Convert.ToInt32(new DBoperate().ExecuteScalar("select Employeeid from Employee where username='"+Session["UserName"]+"'"));
这两句话的区别是什么, 运行时 提示System.Data.SqlClient.SqlException: 列名 'yuguomin' 无效 yuguomin 是用户名  错误的位置是第一句 哪位帮忙解决下

解决方案 »

  1.   

    username字段是字符类型吗?少了个引号int userid = Convert.ToInt32(new DBoperate().ExecuteScalar("select Employeeid from Employee where username='" + Session["UserName"]+"')); 
      

  2.   

    很明显呀 
     where username=" + Session["UserName"]
    上面的语句应该在Session["UserName"]
    的 左右两边加上引号。
      

  3.   

    其实问题是你如何利用前台语言,拼出数据库可用字符串:select Employeeid from Employee where username='UserName'
      

  4.   

    1. "select Employeeid from Employee where username=" + Session["UserName"]); 
    结果是:
    select Employeeid from Employee where username=UserName2. "select Employeeid from Employee where username='"+Session["UserName"]+"'");
    结果才是: 
    select Employeeid from Employee where username=UserName
      

  5.   

    2.结果:select Employeeid from Employee where username='UserName',引号没打上去