一段登陆用的代码,但是出错了。我不知道是什么问题,那位路过的大婶解答一下啊。
            sqlda.Fill(ds, "UTtemp");
就是这句话报错
<appSettings>
    <add key ="connstr"  value="server=Jimmy-PC;uid=sa;pwd=asdf;database=SQLEXPRESS"/>
  </appSettings>
这是web.config里连接的那句话,应该也没错吧。server我用过本机ip,也用过本机名。            UserName = this.TBUser.Text;
            Password = this.TBPW.Text;
            SqlConnection Conn = new SqlConnection(ConfigurationSettings.AppSettings["connstr"]);
            [code=C#]string strcom = "select UserName,Password from UserTable where UserName = '"+UserName+"'";
            SqlDataAdapter sqlda = new SqlDataAdapter(strcom, Conn);
            DataSet ds = new DataSet();
            sqlda.Fill(ds, "UTtemp");
            //this.Label1.Text = 
            if (ds.Tables["UTtemp"].Rows.Count == 0)   //查询结果为空,输入的用户不存在,返回登陆页面
            {
                Response.Write("<script language='javascript'>alert('登录名或密码不正确!');this.document.location='login.aspx';</script>");
                return;            }
[/code]

解决方案 »

  1.   

    路过的大叔给你提示下:
    string conString = System.Configuration.ConfigurationManager.AppSettings["connstr"];
    SqlConnection Conn = new SqlConnection(conString);
      

  2.   

    string strcom = "select UserName,Password from UserTable where UserName = '"+UserName+"'";
    sqlda.Fill(ds, "UTtemp");
    不是一个表?
    报的什么错误
      

  3.   

    4楼,那个UTtemp表只是个别名而已,不要大惊小怪
      

  4.   

    发现好几个问题:
    1,找不到用户,你先将查询语句拷贝到查询分析器看看是否能读出用户;
    2,登录sql应该写为:select count(id) from 用户表 where 用户名='"+用户名变量+"' and 密码='"+密码变量+"'。你的sql语句没有写登录密码
    3,不要将提出的数据放入DataSet,然后用Rows.Count来验证用户,浪费内存资源且效率低。
       应该用SqlCommand 和 一个整型变量来提取用户:
       int hasuser=cmd.ExecuteScalar();
       if (hasuser==1)
       {
         //找到了1个用户,允许登录
       }
       else
       {
         //没有找到用户或找到1个以上用户,禁止登录
       }
      

  5.   

    错误信息
    在与 SQL Server 建立连接时出现与网络相关的或特定于实例的错误。未找到或无法访问服务器。请验证实例名称是否正确并且 SQL Server 已配置为允许远程连接。 (provider: 命名管道提供程序, error: 40 - 无法打开到 SQL Server 的连接)查询分析器里执行命令没有问题啊。
      

  6.   

    囧,原来必须要自己新建一个数据库后才行,我又新建了一个GraduationProject的数据库,连接代码改为
    server=(local)\\SQLEXPRESS;uid=sa;pwd=asdf;database=GraduationProject;
    这次连接正常了,谢谢各位。