.NET
  Home arrow .NET arrow Page 2 - Beginning LINQ to SQL Using Visual Studio ...
ASP Free Forums 
.NET  
ASP  
ASP Code  
ASP.NET  
ASP.NET Code  
BrainDump  
C#  
Code Examples  
Database  
Database Code  
IIS  
Microsoft Access  
MS SQL Server  
Silverlight  
Visual Basic.NET  
Windows Scripting  
Windows Security  
XML  
Mobile Linux 
App Generation ROI 
IBM® developerWorks 
ASP Web Hosting  
ASP.NET Web Hosting 
Windows Web Hosting
 
Weekly Newsletter
 
Developer Updates  
Free Website Content 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us Get Paid 
Request Media Kit
Contact Us 
Site Map 
Privacy Policy 
Support 
 USERNAME
 
 PASSWORD
 
 
  >>> SIGN UP!  
  Lost Password? 
.NET

Beginning LINQ to SQL Using Visual Studio 2008
By: Jagadish Chaterjee
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 5 stars5 stars5 stars5 stars5 stars / 13
    2008-03-31

    Table of Contents:
  • Beginning LINQ to SQL Using Visual Studio 2008
  • Developing a simple LINQ to SQL application (without LINQ designer): UI Design and source in VB.NET
  • Developing a simple LINQ to SQL application (without LINQ designer): source in C#
  • CRUD operations using the LINQ to SQL application (without LINQ designer): UI Design
  • CRUD operations using the LINQ to SQL application (without LINQ designer): Source in VB.NET
  • CRUD operations using the LINQ to SQL application (without LINQ designer): Source in C#

  • Rate this Article: Poor Best 
      ADD THIS ARTICLE TO:
      Del.ici.ous Digg
      Blink Simpy
      Google Spurl
      Y! MyWeb Furl
    Email Me Similar Content When Posted
    Add Developer Shed Article Feed To Your Site
    Email Article To Friend
    Print Version Of Article
    PDF Version Of Article
     
     
    ADVERTISEMENT


    Beginning LINQ to SQL Using Visual Studio 2008 - Developing a simple LINQ to SQL application (without LINQ designer): UI Design and source in VB.NET


    (Page 2 of 6 )

    The following steps are continued from the previous section.

    • Add a reference to "System.Data.Linq" (Go to Project || Add Reference)

    • Add a new class (Project || Add class) to the project and name it "Emp.vb"

    • Copy the following code into it:


    Imports System.Data.Linq.Mapping


    <Table(Name:="emp")> _

    Public Class Emp


    Private _empno As Integer

    <Column(IsPrimaryKey:=True)> _

    Public Property empno() As Integer

    Get

    Return _empno

    End Get

    Set(ByVal value As Integer)

    _empno = value

    End Set

    End Property


    Private _ename As String

    <Column()> _

    Public Property ename() As String

    Get

    Return _ename

    End Get

    Set(ByVal value As String)

    _ename = value

    End Set

    End Property


    Private _sal As Nullable(Of Double)

    <Column()> _

    Public Property Sal() As Nullable(Of Double)

    Get

    Return _sal

    End Get

    Set(ByVal value As Nullable(Of Double))

    _sal = value

    End Set

    End Property


    Private _deptno As Nullable(Of Integer)

    <Column()> _

    Public Property deptno() As Nullable(Of Integer)

    Get

    Return _deptno

    End Get

    Set(ByVal value As Nullable(Of Integer))

    _deptno = value

    End Set

    End Property


    End Class


    • Open "default.aspx", add a GridView and Button controls as follows:


    <body>

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

    <div>

    <asp:Button ID="btnSelectStar" runat="server" Text="Select *" />

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

    </asp:GridView>

    </div>

    </form>

    </body>


    • Open "default.aspx.vb" (code behind) and modify as follows:


    Imports System.Data.Linq

    Partial Public Class _Default

    Inherits System.Web.UI.Page


    Protected Sub btnSelectStar_Click(ByVal sender As Object, ByVal e As EventArgs) Handles btnSelectStar.Click

    Dim db As New DataContext(New System.Data.SqlClient.SqlConnection("data source=.sql2k5;initial catalog=Sample;user id=sa;Password=eXpress2005"))

    Dim tblEmps As Table(Of Emp) = db.GetTable(Of Emp)()

    Me.GridView1.DataSource = tblEmps

    Me.GridView1.DataBind()

    End Sub

    End Class


    Once executed (pressing F5), you should be able to see the output as follows (Fig 4):


    More .NET Articles
    More By Jagadish Chaterjee


       · Hello guys,I am back with a series on "LINQ to SQL" using Visual Studio 2008. ...
       · WHat is that in new LINQ in VS2008.?Can any one explain it..............?
       · i downloaded source code and could not find tables, "emp" and "dept". am i missing...
       · since i'm so new to this i have to ask a stupid question. i downloaded the source...
       · You can find it...
       · You are supposed to create those tables by yourself in your own database. The...
       · thank you very much!! i knew i was missing something.
       · Nice article. it was very useful for me to learn how to work with LINQ
     

    .NET ARTICLES

    - Building Applications with Windows Workflow ...
    - Building the Data and Business Layers Using ...
    - The Transformed XML Explorer in MFC
    - List Control and Property Grid with the MFC ...
    - Font, Shell and Masked Edit Controls for MFC
    - Color, Link and Image Editor Controls for M...
    - New Controls for MFC
    - The Windows Ribbon Framework
    - Markup Language for the Ribbon Framework
    - Visually Upgrade Your MFC Project
    - New Features for the Statusbar in MFC
    - Working with the Statusbar in MFC
    - Iron Speed Design v60 Review
    - Binary and XML Serialization
    - Using CrystalReportViewer to Display Crystal...





    © 2003-2009 by Developer Shed. All rights reserved. DS Cluster 3 Hosted by Hostway
    For more Enterprise Application Development news, visit eWeek