Code: Select all
Imports System.Data
Imports System.Data.Linq
Imports System.Data.Common
Imports System.Transactions
Module Module1
_
Public Class MyDataContext : Inherits DataContext
Public Sub New(ByVal inCnStr As String)
MyBase.New(inCnStr)
End Sub
Public Sub New(ByVal inDatabaseConnection As IDbConnection)
MyBase.New(inDatabaseConnection)
End Sub
Public Customers As Table(Of Customer)
End Class
_
Public Class Customer
Private mCustomerID As String = String.Empty
_
Public Property CustomerID() As String
Get
Return mCustomerID
End Get
Set(ByVal value As String)
mCustomerID = value
End Set
End Property
Private mCustomerName As String = String.Empty
_
Public Property CustomerName() As String
Get
Return mCustomerName
End Get
Set(ByVal value As String)
mCustomerName = value
End Set
End Property
End Class
Sub Main()
Dim mySqlDirectProviderFactory As DbProviderFactory = DbProviderFactories.GetFactory("MySQLDirect.NET Data Provider")
Dim cn As IDbConnection = mySqlDirectProviderFactory.CreateConnection()
Dim cnStr As String = "User Id=usr;Password=pwd;Host=127.0.0.1;Database=test;Pooling=True"
Dim ctx As MyDataContext = New MyDataContext(cn)
Dim i As Integer = 0
cn.ConnectionString = cnStr
Try
ctx.Log = Console.Out
For Each c As Customer In ctx.Customers
Console.WriteLine(c.CustomerID & "," & c.CustomerName)
Next
'Console.WriteLine("Rows affected: " & i.ToString)
Catch ex As Exception
Console.WriteLine("ERROR: " & ex.Message)
End Try
Console.ReadLine()
End Sub
End Module