public string Tallies(string Id, string Pass, string Sort)
    {
        SqlConnection con = new SqlConnection(connstring);
        con.Open();
        if (Sort == "stud")
        {
            SqlCommand sqlcmd = new SqlCommand("select Stud_Id,Stud_Password from [student] where (Sutd_No=Id) and (Stud_Password=Pass) ", con);
            int jl = (Int32)sqlcmd.ExecuteScalar();
(为什么到这里的时候他会说是列名“Stud_No”无效
列名“Id”无效,列名“Pass”无效?,,,数据表中存在Sutd_No,和Stud_Password,怎么会出来Id和Pass这些列?)
            if (jl>0)
            {
                return ("0");
                con.Close();
            }
            else
            {
                return ("1");
                con.Close();
            }        }
        else
        {
            return ("2");
        }

解决方案 »

  1.   

    string sql = "select   Stud_Id,Stud_Password   from   [student]   
                  where   Sutd_No= '"+Id + "'  and   "+
                         "Stud_Password= '"+Pass+"'"; 
     SqlCommand   sqlcmd   =   new   SqlCommand(sql,con); 
      

  2.   

    靠的有点近了 单引号和双引号分不清楚了
    string   sql   =   "select       Stud_Id,Stud_Password       from       [student]       
                                where       Sutd_No=   '  "+Id   +   "  '     and       "+ 
                                              "Stud_Password=   '  "+Pass+" ' ";  
    写的时候不要留空格就好了
      

  3.   

    SqlCommand(sql,conn)执行的就是sql的内容,你把你的那句话拷到查询分析器里面能执行通过么? 显然不行啊
      

  4.   

    1,2,3楼均正解.
    3楼方法,值得参考.
    用1,2楼方法时记得对一下你的Tallies函数参数与数据库字段类型是否有出入.