您的位置:首页 > 数据库

Linq To SQL学习(Part1)

2008-04-08 17:17 274 查看
从今天开始,学习Linq To SQL

数据库:Northwind,如果你的机器上还没有该数据库,点击这儿下载

USE [Northwind]

GO

SET ANSI_NULLS ON

GO

SET QUOTED_IDENTIFIER ON

GO

CREATE PROCEDURE [dbo].[GetProductsByCategory]

@categoryID int

AS

SELECT *

FROM Products

WHERE CategoryID=@categoryID

注:以下代码只是为了做测试,所以在写的过程中没有按照严格的编码规范来写,望谅解。

前台页面:LinqSample.aspx

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

<!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>Product</title>

</head>

<body>

<form id="form1" runat="server">

<div>

<asp:GridView ID="GridView1" runat="server">

</asp:GridView>

<asp:Button ID="Select" runat="server" Text="Show" onclick="Select_Click" />

<asp:Button ID="Update" runat="server" Text="Update" onclick="Update_Click" />

<asp:Button ID="Insert" runat="server" Text="Insert" onclick="Insert_Click" />

<asp:Button ID="Delete" runat="server" Text="Delete" onclick="Delete_Click" />

<asp:Button ID="WithProcedure" runat="server" Text="WithProcedure" onclick="WithProcedure_Click" />

<asp:Button ID="DivisionPage" runat="server" Text="在服务器端分页查询"

onclick="DivisionPage_Click" />

</div>

<div runat="server" id="msg" style="color:Red; font-size:larger"></div>

</form>

</body>

</html>

后台代码:LinqSample.aspx.cs

using System;

using System.Collections;

using System.Configuration;

using System.Data;

using System.Linq;

using System.Web;

using System.Web.Security;

using System.Web.UI;

using System.Web.UI.HtmlControls;

using System.Web.UI.WebControls;

using System.Web.UI.WebControls.WebParts;

using System.Xml.Linq;

public partial class LinqSample : System.Web.UI.Page


[Demo下载]
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: