日期:2014-05-17  浏览次数:20557 次

用数据集写了一个登陆的程序,判断用户名错误的时候报错,求大神教育
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using StudentSetTableAdapters;

public partial class Default2 : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {

    }
    protected void Button1_Click(object sender, EventArgs e)
    {
        studentTableAdapter sta = new studentTableAdapter();
        string name = TextBox1.Text.ToString().Trim();
        StudentSet.studentRow student = sta.GetDataName(name)[0];
        if (student == null)
        {
            (this.Master.FindControl("literal1") as Literal).Text = "用户名不存在";
        }
        else
        {
            string password = TextBox2.Text.ToString().Trim();
            if (password != student.password.Trim())
            {
                (this.Master.FindControl("literal1") as Literal).Text = "密码错误";
            }
            else
            {
                Student s = new Student(student.id, name, password);
                Session.Add("abc", s);
                Response.Redirect("~/loginsucess.aspx");
            }
        }
    }
}
用户名和密码正确,用户名正确密码错误可以实现,但用户名错误,报错
在位置 0 处没有任何行。 
说明: 执行当前 Web 请求期间,出现未处理的异常。请检查堆栈跟踪信息,以了解有关该错误以及代码中导致错误的出处的详细信息。 

异常详细信息: System.IndexOutOfRangeException: 在位置 0 处没有任何行。

源错误: 


行 329:        public studentRow this[int index] {
行 330:            get {
行 331:                return ((studentRow)(this.Rows[index]));
行 332:            }
行 333:        }
 

初学确实不知道