.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  
Visual Basic.NET  
Windows Scripting  
Windows Security  
XML  
ASP Web Hosting  
ASP.NET Web Hosting 
Dedicated Servers 
Actuate Whitepapers 
VeriSign Whitepapers 
Windows Web Hosting
 
IBM® developerWorks 
Sun Developer Network 
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 / 5
    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
     
    Iron Speed
     
    ADVERTISEMENT

    At the virtual BlackBerry Technical Seminar 2008, you can ask your development questions directly of Research In Motion® (RIM) experts, and take advantage of learning opportunities designed uniquely for BlackBerry solution developers. Register Today!

    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..............?
     

    .NET ARTICLES

    - Mouse Input and the WPF
    - Input with Windows Presentation Foundation
    - Introducing LINQ with XML and Databases
    - An Introduction to LINQ
    - Querying LINQ to SQL: Basics
    - Completing a Simple Storefront with LINQ
    - Knowing Your Environment: the System.Environ...
    - Creating the Home Page for a Simple Storefro...
    - LINQ Quickly with Language Integrated Queries
    - Introducing LINQ to SQL Designer using Visua...
    - Beginning LINQ to SQL Using Visual Studio 20...
    - Coding an AjaxPro.NET Based Search Engine fo...
    - Building an AjaxPro.NET Based Search Engine ...
    - Delving Deeper into Serialization with .NET
    - Serialization with .NET





    © 2003-2008 by Developer Shed. All rights reserved. DS Cluster 4 hosted by Hostway