ASP.NET页面链接的问题
我用DataReader实现简单的输出显示,可是当我在页面输入信息点击按钮时就跳转到InternetExplorer无法显示该页面,这是怎么一回事,下面是部分代码,pub...
我用DataReader实现简单的输出显示,可是当我在页面输入信息点击按钮时就跳转到
Internet Explorer 无法显示该页面,这是怎么一回事,下面是部分代码,
public StudentDetails GetStudentByID(int studentId)//这里StudentDetails是一个类,包含的属性有age,name id sex
{
StudentDetails student = new StudentDetails();
SqlDataReader reader;
SqlConnection con = new SqlConnection(connectionString);
string st = string.Format("select * from studentinfo where id={0}", studentId);
SqlCommand cmd = new SqlCommand(st, con);
try
{
con.Open();
reader = cmd.ExecuteReader();
while (reader.Read())
{
student.StudentID = Convert.ToInt32(reader["ID"]);
student.Name = Convert.ToString(reader["Name"]);
student.Age = Convert.ToInt32(reader["Age"]);
student.Sex = Convert.ToString(reader["Sex"]);
}
reader.Close();
}
catch (SqlException ex)
{
student = null;
throw new ApplicationException(ex.Message);
}
finally
{
con.Close();
}
return student;
}
按钮的单击代码:
protected void Button1_Click(object sender, EventArgs e)
{
StudentDB student = new StudentDB();
try
{
int studentId = Convert.ToInt32(this.TextBox1.Text.Trim());
if (studentId > 0)
{
StudentDetails details = new StudentDetails();
details = student.GetStudentByID(studentId);
this.TextBox2.Text = details.Name;
this.TextBox3.Text = details.Sex;
this.TextBox4.Text = details.Age.ToString();
}
else
{
Label5.Visible = true;
Label5.Text = "学生学号必须是正整数";
}
}
catch
{
Label5.Visible = true;
Label5.Text = "学生学号只能是数字";
}
}
} 展开
Internet Explorer 无法显示该页面,这是怎么一回事,下面是部分代码,
public StudentDetails GetStudentByID(int studentId)//这里StudentDetails是一个类,包含的属性有age,name id sex
{
StudentDetails student = new StudentDetails();
SqlDataReader reader;
SqlConnection con = new SqlConnection(connectionString);
string st = string.Format("select * from studentinfo where id={0}", studentId);
SqlCommand cmd = new SqlCommand(st, con);
try
{
con.Open();
reader = cmd.ExecuteReader();
while (reader.Read())
{
student.StudentID = Convert.ToInt32(reader["ID"]);
student.Name = Convert.ToString(reader["Name"]);
student.Age = Convert.ToInt32(reader["Age"]);
student.Sex = Convert.ToString(reader["Sex"]);
}
reader.Close();
}
catch (SqlException ex)
{
student = null;
throw new ApplicationException(ex.Message);
}
finally
{
con.Close();
}
return student;
}
按钮的单击代码:
protected void Button1_Click(object sender, EventArgs e)
{
StudentDB student = new StudentDB();
try
{
int studentId = Convert.ToInt32(this.TextBox1.Text.Trim());
if (studentId > 0)
{
StudentDetails details = new StudentDetails();
details = student.GetStudentByID(studentId);
this.TextBox2.Text = details.Name;
this.TextBox3.Text = details.Sex;
this.TextBox4.Text = details.Age.ToString();
}
else
{
Label5.Visible = true;
Label5.Text = "学生学号必须是正整数";
}
}
catch
{
Label5.Visible = true;
Label5.Text = "学生学号只能是数字";
}
}
} 展开
1个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询