1. Database operations: First create a simple table in the database SPJ
2. Create a new ASP. NET Blank site
3. Create a new Web Form named Showdata.aspx
Add two controls to the source interface: a button control and a GridView control
<div> <asp:button id= "btnshow" runat= "Server" text= "click Show GridView Table" onclick= "Btnshow_click"/> <asp:gridview id= "GridView" runat= "Server" > </asp:GridView> </div>
You can see the design interface
4. Create a new LINQ to SQL class named: DATACLASSES.DBML, make a database connection in Server Explorer, connect to the database in 1, and drag the table SPJ to the design interface
5. Create a new class named: DALShowData.cs
Code:
Using system;using system.collections;using system.collections.generic;using system.linq;using System.Web;///< summary>///Dalshowdata Summary description///</summary>namespace dal{public class Dalshowdata {public IEnumerable daldataquary () { dataclassesdatacontext db=new dataclassesdatacontext (); IEnumerable A = from B in db. SPJ Select New { B.sno, b.pno, b.jno, b.qty }; return A;}}
6. Open the background code Showdata.aspx.cs, write the button click event code
Using system;using system.collections;using system.collections.generic;using system.linq;using System.Web;using System.web.ui;using system.web.ui.webcontrols;using dal;public partial class showdata:system.web.ui.page{ protected void Page_Load (object sender, EventArgs e) { } protected void Btnshow_click (object sender, EventArgs e) { dalshowdata dalshowdata=new dalshowdata (); var data = Dalshowdata.daldataquary (); This. Gridview.datasource = data; This. Gridview.databind (); }}
7. View the showdata.aspx in the browser and view the results
Click the button to see the data for the SPJ table:
Http://www.cnblogs.com/wiming/p/3470300.html