一、打开 Microsoft Visual Studio 2010软件
二、新建一个C#空网站
三、选中项目名(jinlanyan),右键----》添加新项(index.aspx)
四、添加App_Code文件夹,右键项目名(jinlanyan)---》添加asp.net文件夹---》App_Code
五、在App_Code中添加三个普通的文件夹,右键App_Code,选择新建文件夹
六、右键BLL,选择添加新项,依次添加三个类(SubjectBLL.cs、SubjectDAL.cs和SubjectModel.cs),其中SqlHelper.cs为数据库访问类,代码后面给出。
附逻辑说明:index页面调用bll,bll再调用dal,再按顺序返回结果。
七、数据表见下图
八、运行截图
九、各页面代码
index.aspx页面代码
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="index.aspx.cs" Inherits="index" %>
<!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>
<table style="margin: auto;background-color:#33ccff">
<tr>
<td>
按新闻 newsId 查询:<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
</td>
<td>
<asp:Button ID="Button1" runat="server" Text="查询" οnclick="Button1_Click" />
</td>
</tr>
<tr>
<td colspan="2">
<asp:GridView ID="GridView1" runat="server" Style="margin: auto" OnRowDeleting="Subject_RowDeleting1"
OnRowEditing="Subject_RowEditing" OnRowUpdating="Subject_RowUpdating"
onrowcancelingedit="GridView1_RowCancelingEdit">