Bll的设计:MyStudentBll
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using sancenjiagou.sancengjia.DAL;
namespace sancenjiagou.sancengjia.Bll
{
public class MyStudentBll
{
public bool AgeAddById(int fid)
{
MyStudentDAL dal = new MyStudentDAL();
int r = dal.AgeAddById(fid);
if (r > 0)
{
return true;
}
else
{
return false;
}
}
}
}
DAL的设计:MyStudentDAL
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Data.SqlClient;
using _11_28DataSet111;
namespace sancenjiagou.sancengjia.DAL
{
public class MyStudentDAL
{
//本方法是实现某个学生的id加1
public int AgeAddById(int fid)//建立一个方法,实现对表的操作
{
string sql = "update Mystudents set FAge=FAge+1 where FId=@sId";
SqlParameter pms = new SqlParameter("@sId", fid);
return SqlHealper1.ExecuteNonQuery(sql, pms);
}
}
}
UI的.aspx的设计
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="WebForm1.aspx.cs" Inherits="sancenjiagou.sancengjia.UI.WebForm1" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div>
请输入学生的ID:<asp:TextBox ID="txtID" runat="server"></asp:TextBox>
<br />
<br />
<asp:Button ID="Button1" runat="server" οnclick="Button1_Click" Text="该学生的年龄加1"
Width="275px" />
</div>
</form>
</body>
</html>
UI的.aspx.cs的设计
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using sancenjiagou.sancengjia.Bll;
namespace sancenjiagou.sancengjia.UI
{
public partial class WebForm1 : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void Button1_Click(object sender, EventArgs e)
{
int fid = Convert.ToInt32(txtID.Text.Trim());
MyStudentBll bll = new MyStudentBll();
bool b = bll.AgeAddById(fid);
if (b)
{
Response.Write("修改成功");
}
else
{
Response.Write("修改失败");
}
}
}