01.
02.
03.
04.
05.
06.
Imports
System.Data
07.
Imports
System.Data.SqlClient
08.
09.
Public
Partial
Class
MainForm
10.
Public
Sub
New
()
11.
12.
Me
.InitializeComponent()
13.
14.
15.
16.
17.
End
Sub
18.
19.
Sub
Button1Click(sender
As
Object
, e
As
EventArgs)
20.
Dim
dt1
As
New
DataTable
21.
Dim
SqlConn
As
New
SqlConnection
22.
Dim
SqlCmd
As
New
SqlCommand
23.
Dim
SqlWrt
As
New
SqlDataAdapter
24.
Dim
Cmd
As
String
25.
SqlConn.ConnectionString=
" server=*IPหรือชื่อ ของ Server*;database=Northwind;user id=sa"
26.
SqlConn.Open
27.
28.
Cmd=
"select * from Categories"
29.
SqlCmd.CommandText=Cmd
30.
SqlCmd.Connection=SqlConn
31.
sqlWrt.SelectCommand=SqlCmd
32.
sqlWrt.Fill(dt1)
33.
34.
If
dt1.Rows.Count>0
Then
35.
TextBox1.Text=dt1.Rows(0)(
"CategoryName"
)
36.
dataGridView1.DataSource=dt1
37.
End
If
38.
End
Sub
39.
End
Class