LINQ to SQL HOL VB.NET Code

Microsoft offers a hands on lab (HOL) which guides you step by step through creation of a application using LINQ. As always, somebody forgot to show the VB code.

Here it is

Imports System.Data.Linq Imports System.Data.Linq.Mapping

Module Module1

Sub Main()

Dim conn As String = "Data Source=.\sqlexpress;Initial Katalog=Northwind"

Dim db As DataContext = New DataContext(conn)

Dim customers As Table(Of Customer) = db.GetTable(Of Customer)()

db.Log = Console.Out

Dim custs = From c In customers _

Where c.city = "London" _

Select c

For Each cust In custs

Console.WriteLine("ID={0}, City={1}", cust.CustomerID, cust.City)

Next

Console.ReadLine()

End Sub

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

Public Class Customer

<Column(IsPrimarykey:=True)> _

Public customerid As String

Private _city As String

<Column(Storage:="_city")> _

Public Property city() As String

Get

Return _city

End Get

Set(ByVal value As String)

_city = value

End Set

End Property

End Class

End Module

Link to linq HOL

Published Wednesday, January 16, 2008 9:53 AM by preishuber
Filed under: ,

Comments

# Geek Lectures - Things geeks should know about &raquo; Blog Archive &raquo; LINQ to SQL HOL VB.NET Code

Pingback from  Geek Lectures - Things geeks should know about &raquo; Blog Archive   &raquo;  LINQ to SQL HOL VB.NET Code

# hol

Saturday, May 31, 2008 7:11 PM by hol

Pingback from  hol

# re: LINQ to SQL HOL VB.NET Code

Sunday, August 17, 2008 11:40 PM by yatie

I try ur code on my vb.net code.

Can u help me tu manipulate this code on my login page.  TQ.

Private Function YourValidationFunction(ByVal UserName As String, ByVal Password As String) As Boolean

       Dim conn As String = ConfigurationManager.ConnectionStrings("AssignmentConnectionString2").ToString()

Dim db As DataContext = New DataContext(conn)

       Dim Logins As Table(Of Login) = db.GetTable(Of Login)()

       db.Log = Console.Out

       Dim UserName As TextBox

       Dim log = From c In Logins _

                 Where (c.UserName = UserName.text) _

                 Select c

               If (UserName = UserName.ToString()) Then

           Response.Redirect("WebForm1.aspx")

       Else

           Response.Redirect("WebForm2.aspx")

       End If

Leave a Comment

(required) 
(required) 
(optional)
(required)