基础温习(一) ADO.NET之增删查修

回看自己学习.NET以来操作数据库的历史,从萌芽阶段的ADO.NET,自我封装的SQLhelp的懵懂,使用objectDataSource的便捷,Enterprise Library之类的选择,开源ORM的探索,再到现在LINQ和Entity Framework,一路走来深感技术就是第一生产力深刻道理.

这段日子要重新上路了,是时候温习那些风尘已久的ADO.NET代码,再次踏踏实实书写那些增删查修的代码...

今天写的Demo(数据库使用Northwind两个表 Products 和 Categories)

凌乱的界面:)

 1.后台代码:

Product.cs  

 

Category.cs

 

CommonApp.cs

 

DBOperate.cs

2.前台代码

Default.aspx.cs

3.前台页面:

<% @ Page Language="C#" AutoEventWireup="true"  CodeFile="Default.aspx.cs" Inherits="_Default"  %>

<! 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 > ADO.NET Demo </ title >
</ head >
< body >
    
< form  id ="form1"  runat ="server" >
    
< div >
        
< asp:Label  ID ="lbMessage"  runat ="server"  Text ="Label" ></ asp:Label >< br  />
        种类名:
        
< asp:DropDownList  ID ="ddlCategoryName"  runat ="server"  Height ="29px"  
            Width
="126px"  AutoPostBack ="true"   
            onselectedindexchanged
="ddlCategoryName_SelectedIndexChanged"   >
        
</ asp:DropDownList >

        
&nbsp;&nbsp;&nbsp;
        
< asp:Button  ID ="bDeleteCategory"  runat ="server"  Text ="删除该种类"  
            onclick
="bDeleteCategory_Click"   />
&nbsp;&nbsp;
        
< asp:CheckBox  ID ="chkIsIncludeProducts"  Text ="同时删除该种类的产品"  Checked ="true"  runat ="server"   />

        
< br  />
        
< br  />
        输入新的种类名:
< asp:TextBox  ID ="tbUpdateCategoryName"  runat ="server" ></ asp:TextBox >
&nbsp;&nbsp;&nbsp;
        
< asp:Button  ID ="bUpdateCategoryName"  runat ="server"  Text ="更新种类名"  
            onclick
="bUpdateCategoryName_Click"   />
        
< br  />
        
< br  />
        输入新增种类的名称:
< asp:TextBox  ID ="tbCategoryName"  runat ="server" ></ asp:TextBox >

        
< asp:Button  ID ="bInsertCategory"  runat ="server"  Text ="新增种类"  
            onclick
="bInsertCategory_Click"    />

        
< br  />

        
< br  />

        
< br  />
        产品名称:
        
< asp:TextBox  ID ="tbProductName"  runat ="server" ></ asp:TextBox >

        
< asp:Button  ID ="bFindProducts"  runat ="server"  Text ="查找产品"  
            onclick
="bFindProducts_Click"   />
        
&nbsp;&nbsp;
        
< asp:Button  ID ="bDeleteProduct"  runat ="server"  Text ="删除该产品"  
            onclick
="bDeleteProduct_Click"   />
        
        
< br  />
        
< br  />
        
< br  />
        产品名:
< asp:TextBox  ID ="tbInsertProductName"  runat ="server" ></ asp:TextBox >
        
< br  />
        产品单价:
< asp:TextBox  ID ="tbInsertProductUnitPrice"  runat ="server" ></ asp:TextBox >
        
< br  />
        产品种类:
< asp:DropDownList  ID ="ddlCategoryName2"  runat ="server"  Height ="29px"  
            Width
="126
            px"
>
        
</ asp:DropDownList >
        
< br  />
        
< asp:Button  ID ="bInsertProduct"  runat ="server"  Text ="添加产品"  
            onclick
="bInsertProduct_Click"   />
        
< br  />
        
< br  />
        
< asp:GridView  ID ="gvProducts"  runat ="server" >
        
</ asp:GridView >
    
</ div >
    
</ form >
</ body >
</ html >
  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值