使用三层架构,实现页面中输入学生id,单机按钮后使该学生的年龄加
UI文件夹/ui1.aspx前台:
<body>
<form id="form1" runat="server">
<div>
请输入要修改学生年龄的id:<asp:TextBox ID="txtId" runat="server"></asp:TextBox>
<br /><br />
<asp:Button ID="Button1" runat="server" onclick="Button1_Click" Text="学生年龄加1" />
</div>
</form>
</body>
UI文件夹/ui1.aspx后台:
protected void Button1_Click(object sender, EventArgs e)
{
int fid = Convert.ToInt32(txtId.Text.Trim());
MyStudentsBll bll = new MyStudentsBll();
bool b = bll.AgeAddById(fid);
if (b)
{
Response.Write("修改成功!");
}
else
{
Response.Write("修改失败!");
}
}
DAL/MyStudentsDal类:
public class MyStudentsDal
{
public int AgeAddById(int Fid)
{
string sql = "update MyStudents set FAge=FAge+1 where FId=@Fid";
SqlParameter pms = new SqlParameter("@Fid",Fid);
return SQLHelper.ExecuteNoQuery(sql, pms);
}
}
Bll/MyStudentsBll类:
public class MyStudentsBll
{
public bool AgeAddById(int fid)
{
MyStudentsDal dal = new MyStudentsDal();
int r=dal.AgeAddById(fid);
if (r > 0)
{
return true;
}
else
{
return false;
}
}
}