步步為營VS 2008 + .NET 3.5(8) - DLINQ(LINQ to SQL)之面向對象的添加、查詢、更新和刪除
作者:webabcd
介紹
以Northwind為示例數據庫,DLINQ(LINQ to SQL)之完全面向對象的添加操作、查詢操作、更新操作和刪除操作
示例
Sample.aspx
<%@ Page Language="C#" MasterPageFile="~/Site.master" AutoEventWireup="true" CodeFile="Sample.aspx.cs"
????????Inherits="LINQ_DLINQ_Sample" Title="面向對象的添加、查詢、更新和刪除" %>
<asp:Content ID="Content1" ContentPlaceHolderID="head" runat="Server">
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" runat="Server">
????????<p>
????????????????分類名稱:<asp:TextBox ID="txtCategoryName" runat="server"></asp:TextBox>
?????????????????? 分類描述:<asp:TextBox ID="txtDescription" runat="server"></asp:TextBox>
??????????????????
????????????????<asp:Button ID="btnAdd" runat="server" Text="添加" OnClick="btnAdd_Click" />
????????</p>
????????<asp:GridView ID="gvCategory" runat="server" DataKeyNames="CategoryID" OnSelectedIndexChanged="gvCategory_SelectedIndexChanged"
????????????????OnRowDeleting="gvCategory_RowDeleting" OnRowCancelingEdit="gvCategory_RowCancelingEdit"
????????????????OnRowEditing="gvCategory_RowEditing" OnRowUpdating="gvCategory_RowUpdating">
????????????????<Columns>
????????????????????????<asp:CommandField ShowSelectButton="True" ShowEditButton="True" ShowDeleteButton="True">
????????????????????????</asp:CommandField>
????????????????</Columns>
????????</asp:GridView>
????????<br />
????????<asp:DetailsView ID="dvProduct" runat="server" DataKeyNames="ProductID">
????????</asp:DetailsView>
</asp:Content>
????????Inherits="LINQ_DLINQ_Sample" Title="面向對象的添加、查詢、更新和刪除" %>
<asp:Content ID="Content1" ContentPlaceHolderID="head" runat="Server">
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" runat="Server">
????????<p>
????????????????分類名稱:<asp:TextBox ID="txtCategoryName" runat="server"></asp:TextBox>
?????????????????? 分類描述:<asp:TextBox ID="txtDescription" runat="server"></asp:TextBox>
??????????????????
????????????????<asp:Button ID="btnAdd" runat="server" Text="添加" OnClick="btnAdd_Click" />
????????</p>
????????<asp:GridView ID="gvCategory" runat="server" DataKeyNames="CategoryID" OnSelectedIndexChanged="gvCategory_SelectedIndexChanged"
????????????????OnRowDeleting="gvCategory_RowDeleting" OnRowCancelingEdit="gvCategory_RowCancelingEdit"
????????????????OnRowEditing="gvCategory_RowEditing" OnRowUpdating="gvCategory_RowUpdating">
????????????????<Columns>
????????????????????????<asp:CommandField ShowSelectButton="True" ShowEditButton="True" ShowDeleteButton="True">
????????????????????????</asp:CommandField>
????????????????</Columns>
????????</asp:GridView>
????????<br />
????????<asp:DetailsView ID="dvProduct" runat="server" DataKeyNames="ProductID">
????????</asp:DetailsView>
</asp:Content>
Sample.aspx.cs
















































































































OK
[源碼下載]
?
本文出自 “webabcd” 博客,請務必保留此出處http://webabcd.blog.51cto.com/1787395/345006