| ตัวอย่าง code ที่เรียน .net กับ อ.ธนัท ผุดกระจ่าง
 สำหรับเชื่อมต่อฐานข้อมูลแบบพิมพ์ code
 Option Strict On
 Option Explicit On
 Imports System
 Imports System.Data.SqlClient
 Imports Microsoft.VisualBasic
 
 Module Module1
 Public Function fncconnectiondb() As SqlConnection
 Dim mycon As String
 Dim mycondb As New SqlConnection
 Try
 mycon = "Data Source=lab322\SQLExpress;Initial Catalog=Northwind;Integrated Security=True"
 mycondb.ConnectionString = mycon
 If mycondb.State = ConnectionState.Closed Then
 mycondb.Open()
 End If
 Catch ex As Exception
 'MessageBox.Show(ex.ToString)
 MsgBox(ex.ToString)
 End Try
 Return mycondb
 End Function
 End Module
 
 
 
 |