Infolink

 

Search This Blog

Nov 10, 2012

Linq To Sql Demo

Web.Config

<appSettings>
    <add key="constr" value="Data Source = machine/server;
    Initial Catalog=DatabaseName;User ID=userid; password=password"/>
  </appSettings>
    <connectionStrings>
  <add name="TradeplusConnectionString" connectionString="Data Source = machine/server;Initial Catalog=DatabaseName;User ID=userid; password=password"
       providerName="System.Data.SqlClient" />
 </connectionStrings>


LinqDemo.aspx

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="LinqDemo.aspx.cs" Inherits="LinqDemo" %> <!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>     <asp:GridView runat="server" ID="GV"></asp:GridView>     </div>     </form> </body> </html>
LinqDemo.aspx.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.Services;
public partial class LinqDemo : System.Web.UI.Page
    protected void Page_Load(object sender, EventArgs e)
    {
        ViewData();
    }
    private void ViewData()
    {
       
        DataClassesDataContext db=new DataClassesDataContext();
       
        db.Connection.ConnectionString =
        System.Configuration.ConfigurationManager.AppSettings["constr"];
        var country =
            from c in db.PB_HoldBroks
            select c;
        GV.DataSource = country;
        GV.DataBind();
    }
}

No comments:

Post a Comment

Related Posts Plugin for WordPress, Blogger...