说明: 执行当前 Web 请求期间,出现未处理的异常。请检查堆栈跟踪信息,以了解有关该错误以及代码中导致错误的出处的详细信息。
异常详细信息: System.IndexOutOfRangeException: 在位置 0 处没有任何行。
源错误:
行 37: SqlDataAdapter da = new SqlDataAdapter(sql, sqlConn);
行 38: da.Fill(ds);
行 39: if (txt_Password.Text.ToString().Trim() == ds.Tables[0].Rows[0]["密码"] && txt_Username.Text.ToString().Trim() == ds.Tables[0].Rows[0]["账号"])
行 40: {
行 41: //Response.Write("<script>alert('登陆成功!');</script>");
源文件: c:\Documents and Settings\Administrator\桌面\人事信息\login.aspx.cs 行: 39
堆栈跟踪:
[IndexOutOfRangeException: 在位置 0 处没有任何行。]
System.Data.RBTree`1.GetNodeByIndex(Int32 userIndex) +1943315
System.Data.RBTree`1.get_Item(Int32 index) +17
System.Data.DataRowCollection.get_Item(Int32 index) +11
login.Button1_Click(Object sender, EventArgs e) in c:\Documents and Settings\Administrator\桌面\人事信息\login.aspx.cs:39
System.Web.UI.WebControls.Button.OnClick(EventArgs e) +105
System.Web.UI.WebControls.Button.RaisePostBackEvent(String eventArgument) +107
System.Web.UI.WebControls.Button.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String eventArgument) +7
System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument) +11
System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData) +33
System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +1746
20 个解决方案
#1
if(ds.Tables[0].Rows.Count>0)
{
if (txt_Password.Text.ToString().Trim().Equals(ds.Tables[0].Rows[0]["密码"].ToString()) && txt_Username.Text.ToString().Trim().Equals(ds.Tables[0].Rows[0]["账号"].ToString()))
{}
}
{
if (txt_Password.Text.ToString().Trim().Equals(ds.Tables[0].Rows[0]["密码"].ToString()) && txt_Username.Text.ToString().Trim().Equals(ds.Tables[0].Rows[0]["账号"].ToString()))
{}
}
#2
if(ds.Tables[0].Rows.Count>0)
判断一下表中有没有数据。
判断一下表中有没有数据。
#3
if(ds.Tables[0].Rows.Count>0)
可能是table[0]中没有数据
可能是table[0]中没有数据
#4
调试一下,看看你的那个ds是不是有数据。
#5
先判断ds.Tables[0].Rows[0]["密码"] 是否为null
#6
这个是我的登录按钮的代码,当账号密码正确他进去的是一张空白页,错误的话就还是原来LOGIN页面,很困扰
protected void Button1_Click(object sender, EventArgs e)
{
if (txt_Username.Text.Trim() == "" || txt_Password.Text.Trim() == "")
{
Response.Write("<script>alert('请输入用户名或密码!');</script>");
}
else if (txt_Password.Text.Trim() != "" && txt_Username.Text.Trim() != "")
{
string connStr = "server=localhost;database=PMIS;uid=sa;password=19871216";
string sql = "select 账号,密码 from users where 账号='" + txt_Username.Text.ToString().Trim() + " 'and 密码='" + txt_Password.Text.ToString().Trim() + "'";
SqlConnection sqlConn = new SqlConnection(connStr);
DataSet ds = new DataSet();
SqlDataAdapter da = new SqlDataAdapter(sql, sqlConn);
da.Fill(ds);
if (ds.Tables[0].Rows.Count > 0)
{
if (txt_Password.Text.ToString().Trim() == ds.Tables[0].Rows[0]["密码"] && txt_Username.Text.ToString().Trim() == ds.Tables[0].Rows[0]["账号"])
{
//Response.Write("<script>alert('登陆成功!');</script>");
//跳转页面
Response.Write("<script>alert(登陆成功!3秒后将跳转到主页面。'');window.location.href='~/index.aspx';</script>");
}
else
{
Response.Write("<script>alert('用户名或密码不正确!请重新输入!');</>");
}
}
}
}
protected void Button1_Click(object sender, EventArgs e)
{
if (txt_Username.Text.Trim() == "" || txt_Password.Text.Trim() == "")
{
Response.Write("<script>alert('请输入用户名或密码!');</script>");
}
else if (txt_Password.Text.Trim() != "" && txt_Username.Text.Trim() != "")
{
string connStr = "server=localhost;database=PMIS;uid=sa;password=19871216";
string sql = "select 账号,密码 from users where 账号='" + txt_Username.Text.ToString().Trim() + " 'and 密码='" + txt_Password.Text.ToString().Trim() + "'";
SqlConnection sqlConn = new SqlConnection(connStr);
DataSet ds = new DataSet();
SqlDataAdapter da = new SqlDataAdapter(sql, sqlConn);
da.Fill(ds);
if (ds.Tables[0].Rows.Count > 0)
{
if (txt_Password.Text.ToString().Trim() == ds.Tables[0].Rows[0]["密码"] && txt_Username.Text.ToString().Trim() == ds.Tables[0].Rows[0]["账号"])
{
//Response.Write("<script>alert('登陆成功!');</script>");
//跳转页面
Response.Write("<script>alert(登陆成功!3秒后将跳转到主页面。'');window.location.href='~/index.aspx';</script>");
}
else
{
Response.Write("<script>alert('用户名或密码不正确!请重新输入!');</>");
}
}
}
}
#7
Response.Write(" <script>alert(登陆成功!3秒后将跳转到主页面。'');window.location.href='~/index.aspx'; </script>");
window.location = 'index.aspx相对当前login.aspx的路径'
Response.Write(" <script>alert('用户名或密码不正确!请重新输入!'); </>");
上面少写了个</script>
window.location = 'index.aspx相对当前login.aspx的路径'
Response.Write(" <script>alert('用户名或密码不正确!请重新输入!'); </>");
上面少写了个</script>
#8
Response.Write(" <script>alert(登陆成功!3秒后将跳转到主页面。'');setTimeOut(function(){window.location.href='~/index.aspx';},3000); </script>");
#9
我改成这样还有同样的情况,麻烦帮我LOOK下
protected void Button1_Click(object sender, EventArgs e)
{
if (txt_Username.Text.Trim() == "" || txt_Password.Text.Trim() == "")
{
Response.Write("<script>alert('请输入用户名或密码!');</script>");
}
else if (txt_Password.Text.Trim() != "" && txt_Username.Text.Trim() != "")
{
string connStr = "server=localhost;database=PMIS;uid=sa;password=19871216";
string sql = "select 账号,密码 from users where 账号='" + txt_Username.Text.ToString().Trim() + " 'and 密码='" + txt_Password.Text.ToString().Trim() + "'";
SqlConnection sqlConn = new SqlConnection(connStr);
DataSet ds = new DataSet();
SqlDataAdapter da = new SqlDataAdapter(sql, sqlConn);
da.Fill(ds);
if (ds.Tables[0].Rows.Count > 0)
{
if (txt_Password.Text.ToString().Trim() == ds.Tables[0].Rows[0]["密码"] && txt_Username.Text.ToString().Trim() == ds.Tables[0].Rows[0]["账号"])
{
Response.Redirect("~/admin.aspx");
}
else
{
Response.Write("<script>alert('用户名或密码不正确!请重新输入!');<script/>");
}
}
}
}
protected void Button1_Click(object sender, EventArgs e)
{
if (txt_Username.Text.Trim() == "" || txt_Password.Text.Trim() == "")
{
Response.Write("<script>alert('请输入用户名或密码!');</script>");
}
else if (txt_Password.Text.Trim() != "" && txt_Username.Text.Trim() != "")
{
string connStr = "server=localhost;database=PMIS;uid=sa;password=19871216";
string sql = "select 账号,密码 from users where 账号='" + txt_Username.Text.ToString().Trim() + " 'and 密码='" + txt_Password.Text.ToString().Trim() + "'";
SqlConnection sqlConn = new SqlConnection(connStr);
DataSet ds = new DataSet();
SqlDataAdapter da = new SqlDataAdapter(sql, sqlConn);
da.Fill(ds);
if (ds.Tables[0].Rows.Count > 0)
{
if (txt_Password.Text.ToString().Trim() == ds.Tables[0].Rows[0]["密码"] && txt_Username.Text.ToString().Trim() == ds.Tables[0].Rows[0]["账号"])
{
Response.Redirect("~/admin.aspx");
}
else
{
Response.Write("<script>alert('用户名或密码不正确!请重新输入!');<script/>");
}
}
}
}
#10
dataset为空,没取到数据
#11
那怎么办 我改不来!!
#12
#13
你没有取出符合条件的数据。datasouce 为空
加上
加上
if(ds.Tables[0].Rows.Count>0)
{
if (txt_Password.Text.ToString().Trim().Equals(ds.Tables[0].Rows[0]["密码"].ToString()) && txt_Username.Text.ToString().Trim().Equals(ds.Tables[0].Rows[0]["账号"].ToString()))
{}
}
#14
我已经有判断if (ds.Tables[0].Rows.Count > 0)
#15
在数据库没有查询记录的时候,没有输出提示信息
if (ds.Tables[0].Rows.Count > 0)
{
}
else
{
Response.Write(" <script>alert('用户名或密码不正确!请重新输入!'); <script/>");
}
if (ds.Tables[0].Rows.Count > 0)
{
}
else
{
Response.Write(" <script>alert('用户名或密码不正确!请重新输入!'); <script/>");
}
#16
应该是dataset为空.你可以加个,如果为空,几绑定个空的,这样不要赋值,不然会错
#17
rows.count 不为空 登录成功 否则 登录失败 !
你的代码 多余了呀!!
txt_Password.Text.ToString().Trim() == ds.Tables[0].Rows[0]["密码"] && txt_Username.Text.ToString().Trim() == ds.Tables[0].Rows[0]["账号"] 肯定是true 呀
#18
你try catch一下,将异常显示出来,同时将sql数据,在查询分析器里看看能否查东西来。
#19
我现在账号密码正确的话可以进我的admin.aspx页面了,但是错误的话那个“账号密码不正确”那框跳不出来
protected void Button1_Click(object sender, EventArgs e)
{
if (txt_Username.Text.Trim() == "" || txt_Password.Text.Trim() == "")
{
Response.Write("<script>alert('请输入用户名或密码!');</script>");
}
else if (txt_Password.Text.Trim() != "" && txt_Username.Text.Trim() != "")
{
string connStr = "server=localhost;database=PMIS;uid=sa;password=19871216";
string sql = "select 账号,密码 from users where 账号='" + txt_Username.Text.ToString().Trim() + " 'and 密码='" + txt_Password.Text.ToString().Trim() + "'";
SqlConnection sqlConn = new SqlConnection(connStr);
DataSet ds = new DataSet();
SqlDataAdapter da = new SqlDataAdapter(sql, sqlConn);
da.Fill(ds);
if (ds.Tables[0].Rows.Count > 0)
{
Response.Redirect("~/admin.aspx");
}
else
{
Response.Redirect("~/login.aspx");
Response.Write("<script>alert('请输入用户名或密码!');</script>");
}
}
}
protected void Button1_Click(object sender, EventArgs e)
{
if (txt_Username.Text.Trim() == "" || txt_Password.Text.Trim() == "")
{
Response.Write("<script>alert('请输入用户名或密码!');</script>");
}
else if (txt_Password.Text.Trim() != "" && txt_Username.Text.Trim() != "")
{
string connStr = "server=localhost;database=PMIS;uid=sa;password=19871216";
string sql = "select 账号,密码 from users where 账号='" + txt_Username.Text.ToString().Trim() + " 'and 密码='" + txt_Password.Text.ToString().Trim() + "'";
SqlConnection sqlConn = new SqlConnection(connStr);
DataSet ds = new DataSet();
SqlDataAdapter da = new SqlDataAdapter(sql, sqlConn);
da.Fill(ds);
if (ds.Tables[0].Rows.Count > 0)
{
Response.Redirect("~/admin.aspx");
}
else
{
Response.Redirect("~/login.aspx");
Response.Write("<script>alert('请输入用户名或密码!');</script>");
}
}
}
#20
else
{ //倒过来:
Response.Write(" <script>alert('请输入用户名或密码!'); </script>");
Response.Redirect("~/login.aspx");
}
{ //倒过来:
Response.Write(" <script>alert('请输入用户名或密码!'); </script>");
Response.Redirect("~/login.aspx");
}
#21
#1
if(ds.Tables[0].Rows.Count>0)
{
if (txt_Password.Text.ToString().Trim().Equals(ds.Tables[0].Rows[0]["密码"].ToString()) && txt_Username.Text.ToString().Trim().Equals(ds.Tables[0].Rows[0]["账号"].ToString()))
{}
}
{
if (txt_Password.Text.ToString().Trim().Equals(ds.Tables[0].Rows[0]["密码"].ToString()) && txt_Username.Text.ToString().Trim().Equals(ds.Tables[0].Rows[0]["账号"].ToString()))
{}
}
#2
if(ds.Tables[0].Rows.Count>0)
判断一下表中有没有数据。
判断一下表中有没有数据。
#3
if(ds.Tables[0].Rows.Count>0)
可能是table[0]中没有数据
可能是table[0]中没有数据
#4
调试一下,看看你的那个ds是不是有数据。
#5
先判断ds.Tables[0].Rows[0]["密码"] 是否为null
#6
这个是我的登录按钮的代码,当账号密码正确他进去的是一张空白页,错误的话就还是原来LOGIN页面,很困扰
protected void Button1_Click(object sender, EventArgs e)
{
if (txt_Username.Text.Trim() == "" || txt_Password.Text.Trim() == "")
{
Response.Write("<script>alert('请输入用户名或密码!');</script>");
}
else if (txt_Password.Text.Trim() != "" && txt_Username.Text.Trim() != "")
{
string connStr = "server=localhost;database=PMIS;uid=sa;password=19871216";
string sql = "select 账号,密码 from users where 账号='" + txt_Username.Text.ToString().Trim() + " 'and 密码='" + txt_Password.Text.ToString().Trim() + "'";
SqlConnection sqlConn = new SqlConnection(connStr);
DataSet ds = new DataSet();
SqlDataAdapter da = new SqlDataAdapter(sql, sqlConn);
da.Fill(ds);
if (ds.Tables[0].Rows.Count > 0)
{
if (txt_Password.Text.ToString().Trim() == ds.Tables[0].Rows[0]["密码"] && txt_Username.Text.ToString().Trim() == ds.Tables[0].Rows[0]["账号"])
{
//Response.Write("<script>alert('登陆成功!');</script>");
//跳转页面
Response.Write("<script>alert(登陆成功!3秒后将跳转到主页面。'');window.location.href='~/index.aspx';</script>");
}
else
{
Response.Write("<script>alert('用户名或密码不正确!请重新输入!');</>");
}
}
}
}
protected void Button1_Click(object sender, EventArgs e)
{
if (txt_Username.Text.Trim() == "" || txt_Password.Text.Trim() == "")
{
Response.Write("<script>alert('请输入用户名或密码!');</script>");
}
else if (txt_Password.Text.Trim() != "" && txt_Username.Text.Trim() != "")
{
string connStr = "server=localhost;database=PMIS;uid=sa;password=19871216";
string sql = "select 账号,密码 from users where 账号='" + txt_Username.Text.ToString().Trim() + " 'and 密码='" + txt_Password.Text.ToString().Trim() + "'";
SqlConnection sqlConn = new SqlConnection(connStr);
DataSet ds = new DataSet();
SqlDataAdapter da = new SqlDataAdapter(sql, sqlConn);
da.Fill(ds);
if (ds.Tables[0].Rows.Count > 0)
{
if (txt_Password.Text.ToString().Trim() == ds.Tables[0].Rows[0]["密码"] && txt_Username.Text.ToString().Trim() == ds.Tables[0].Rows[0]["账号"])
{
//Response.Write("<script>alert('登陆成功!');</script>");
//跳转页面
Response.Write("<script>alert(登陆成功!3秒后将跳转到主页面。'');window.location.href='~/index.aspx';</script>");
}
else
{
Response.Write("<script>alert('用户名或密码不正确!请重新输入!');</>");
}
}
}
}
#7
Response.Write(" <script>alert(登陆成功!3秒后将跳转到主页面。'');window.location.href='~/index.aspx'; </script>");
window.location = 'index.aspx相对当前login.aspx的路径'
Response.Write(" <script>alert('用户名或密码不正确!请重新输入!'); </>");
上面少写了个</script>
window.location = 'index.aspx相对当前login.aspx的路径'
Response.Write(" <script>alert('用户名或密码不正确!请重新输入!'); </>");
上面少写了个</script>
#8
Response.Write(" <script>alert(登陆成功!3秒后将跳转到主页面。'');setTimeOut(function(){window.location.href='~/index.aspx';},3000); </script>");
#9
我改成这样还有同样的情况,麻烦帮我LOOK下
protected void Button1_Click(object sender, EventArgs e)
{
if (txt_Username.Text.Trim() == "" || txt_Password.Text.Trim() == "")
{
Response.Write("<script>alert('请输入用户名或密码!');</script>");
}
else if (txt_Password.Text.Trim() != "" && txt_Username.Text.Trim() != "")
{
string connStr = "server=localhost;database=PMIS;uid=sa;password=19871216";
string sql = "select 账号,密码 from users where 账号='" + txt_Username.Text.ToString().Trim() + " 'and 密码='" + txt_Password.Text.ToString().Trim() + "'";
SqlConnection sqlConn = new SqlConnection(connStr);
DataSet ds = new DataSet();
SqlDataAdapter da = new SqlDataAdapter(sql, sqlConn);
da.Fill(ds);
if (ds.Tables[0].Rows.Count > 0)
{
if (txt_Password.Text.ToString().Trim() == ds.Tables[0].Rows[0]["密码"] && txt_Username.Text.ToString().Trim() == ds.Tables[0].Rows[0]["账号"])
{
Response.Redirect("~/admin.aspx");
}
else
{
Response.Write("<script>alert('用户名或密码不正确!请重新输入!');<script/>");
}
}
}
}
protected void Button1_Click(object sender, EventArgs e)
{
if (txt_Username.Text.Trim() == "" || txt_Password.Text.Trim() == "")
{
Response.Write("<script>alert('请输入用户名或密码!');</script>");
}
else if (txt_Password.Text.Trim() != "" && txt_Username.Text.Trim() != "")
{
string connStr = "server=localhost;database=PMIS;uid=sa;password=19871216";
string sql = "select 账号,密码 from users where 账号='" + txt_Username.Text.ToString().Trim() + " 'and 密码='" + txt_Password.Text.ToString().Trim() + "'";
SqlConnection sqlConn = new SqlConnection(connStr);
DataSet ds = new DataSet();
SqlDataAdapter da = new SqlDataAdapter(sql, sqlConn);
da.Fill(ds);
if (ds.Tables[0].Rows.Count > 0)
{
if (txt_Password.Text.ToString().Trim() == ds.Tables[0].Rows[0]["密码"] && txt_Username.Text.ToString().Trim() == ds.Tables[0].Rows[0]["账号"])
{
Response.Redirect("~/admin.aspx");
}
else
{
Response.Write("<script>alert('用户名或密码不正确!请重新输入!');<script/>");
}
}
}
}
#10
dataset为空,没取到数据
#11
那怎么办 我改不来!!
#12
#13
你没有取出符合条件的数据。datasouce 为空
加上
加上
if(ds.Tables[0].Rows.Count>0)
{
if (txt_Password.Text.ToString().Trim().Equals(ds.Tables[0].Rows[0]["密码"].ToString()) && txt_Username.Text.ToString().Trim().Equals(ds.Tables[0].Rows[0]["账号"].ToString()))
{}
}
#14
我已经有判断if (ds.Tables[0].Rows.Count > 0)
#15
在数据库没有查询记录的时候,没有输出提示信息
if (ds.Tables[0].Rows.Count > 0)
{
}
else
{
Response.Write(" <script>alert('用户名或密码不正确!请重新输入!'); <script/>");
}
if (ds.Tables[0].Rows.Count > 0)
{
}
else
{
Response.Write(" <script>alert('用户名或密码不正确!请重新输入!'); <script/>");
}
#16
应该是dataset为空.你可以加个,如果为空,几绑定个空的,这样不要赋值,不然会错
#17
rows.count 不为空 登录成功 否则 登录失败 !
你的代码 多余了呀!!
txt_Password.Text.ToString().Trim() == ds.Tables[0].Rows[0]["密码"] && txt_Username.Text.ToString().Trim() == ds.Tables[0].Rows[0]["账号"] 肯定是true 呀
#18
你try catch一下,将异常显示出来,同时将sql数据,在查询分析器里看看能否查东西来。
#19
我现在账号密码正确的话可以进我的admin.aspx页面了,但是错误的话那个“账号密码不正确”那框跳不出来
protected void Button1_Click(object sender, EventArgs e)
{
if (txt_Username.Text.Trim() == "" || txt_Password.Text.Trim() == "")
{
Response.Write("<script>alert('请输入用户名或密码!');</script>");
}
else if (txt_Password.Text.Trim() != "" && txt_Username.Text.Trim() != "")
{
string connStr = "server=localhost;database=PMIS;uid=sa;password=19871216";
string sql = "select 账号,密码 from users where 账号='" + txt_Username.Text.ToString().Trim() + " 'and 密码='" + txt_Password.Text.ToString().Trim() + "'";
SqlConnection sqlConn = new SqlConnection(connStr);
DataSet ds = new DataSet();
SqlDataAdapter da = new SqlDataAdapter(sql, sqlConn);
da.Fill(ds);
if (ds.Tables[0].Rows.Count > 0)
{
Response.Redirect("~/admin.aspx");
}
else
{
Response.Redirect("~/login.aspx");
Response.Write("<script>alert('请输入用户名或密码!');</script>");
}
}
}
protected void Button1_Click(object sender, EventArgs e)
{
if (txt_Username.Text.Trim() == "" || txt_Password.Text.Trim() == "")
{
Response.Write("<script>alert('请输入用户名或密码!');</script>");
}
else if (txt_Password.Text.Trim() != "" && txt_Username.Text.Trim() != "")
{
string connStr = "server=localhost;database=PMIS;uid=sa;password=19871216";
string sql = "select 账号,密码 from users where 账号='" + txt_Username.Text.ToString().Trim() + " 'and 密码='" + txt_Password.Text.ToString().Trim() + "'";
SqlConnection sqlConn = new SqlConnection(connStr);
DataSet ds = new DataSet();
SqlDataAdapter da = new SqlDataAdapter(sql, sqlConn);
da.Fill(ds);
if (ds.Tables[0].Rows.Count > 0)
{
Response.Redirect("~/admin.aspx");
}
else
{
Response.Redirect("~/login.aspx");
Response.Write("<script>alert('请输入用户名或密码!');</script>");
}
}
}
#20
else
{ //倒过来:
Response.Write(" <script>alert('请输入用户名或密码!'); </script>");
Response.Redirect("~/login.aspx");
}
{ //倒过来:
Response.Write(" <script>alert('请输入用户名或密码!'); </script>");
Response.Redirect("~/login.aspx");
}