LINQ 連線 Template I
– 在 Server Explorer 上建立好 與 Database Server 既 接口 ( 我用既係 SQL Server 2005 )
– Add Windows Form -> LINQ to SQL Classes
– 係新建立既 Database 列表上 -> Tables -> 將要用既 Table 拖入去 新建立既 <LINQ to SQL Classes> 上面 .
( File Extension: dbml )
– 係 同一個 Project 上既任何一個 Windows Form 內加上下列既 Code . (我用左DataGrid既)
Imports System.Data.SqlClient
……………………………………………………
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim db As New DataClasses1DataContext()
Dim ord As Object
ord = (From p In db.Batches, a In db.Customers Where a.Customer_ID = p.Customer_ID Select p.Batch_ID, p.Batch_Name, a.Customer_Name)
DataGridView1.DataSource = ord
End Sub