Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/313.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/asp.net/36.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 从access数据库访问两列时发生IndexAutoFrange异常_C#_Asp.net_Vb.net_Ms Access - Fatal编程技术网

C# 从access数据库访问两列时发生IndexAutoFrange异常

C# 从access数据库访问两列时发生IndexAutoFrange异常,c#,asp.net,vb.net,ms-access,C#,Asp.net,Vb.net,Ms Access,当我尝试比较用户名(usernam)和密码(passwd)时,我得到了这个错误。 如果我只比较用户名和数据库条目,它就像一个符咒 它只会在使用实际数据时给出错误。 E.I.如果我在登录网页中输入[admin],[admin],它将给出错误信息,如果我输入[asd],[asd],则标签将更改为NO 代码背后的想法是一个登录页面。 我希望我的解释足够好。您只是从表中选择用户名。您没有选择密码,因此当您尝试从结果集中检索密码时,它会引发异常 将查询更改为: while (reader.Read())

当我尝试比较用户名(usernam)和密码(passwd)时,我得到了这个错误。 如果我只比较用户名和数据库条目,它就像一个符咒

它只会在使用实际数据时给出错误。 E.I.如果我在登录网页中输入[admin],[admin],它将给出错误信息,如果我输入[asd],[asd],则标签将更改为NO

代码背后的想法是一个登录页面。
我希望我的解释足够好。

您只是从表中选择用户名。您没有选择密码,因此当您尝试从结果集中检索密码时,它会引发异常

将查询更改为:

while (reader.Read())
{
    if (TextBox1.Text.CompareTo(reader["usernam"].ToString()) == 0&&TextBox2.Text.CompareTo(reader["passwd"].ToString()) == 0) // A little messy but does the job to compare your infos assuming your using a textbox for username and password
    {
        Label3.Text = "Redirecting";



        Response.Cookies["dbname"]["Name"] = reader["usernam"].ToString();
        Response.Cookies["dbname"].Expires = DateTime.Now.AddSeconds(10);
        Response.Redirect("index2.aspx");

    }
    else
    { Label3.Text = "NO"; }

}

您还可以在查询中使用*而不是列名。这里只是一个小场景。如果有多个列,则只需使用*即可。这将使您的查询变得简单。

请将实际代码作为文本添加到您的问题中。
string selectString = "SELECT usernam, passwd FROM Table1";