วิธีนี้ไม่ Work ครับ ให้ออกแบบ Class Database ดีกว่าครับ ตามตัวอย่างนี้ครับ ผมเขียนไว้แล้วครับ
Code (VB.NET)
Imports System.Data
Imports MySql.Data.MySqlClient
Imports System.Configuration
Public Class clsDatabase
Private objConn As MySqlConnection
Private objCmd As MySqlCommand
Private Trans As MySqlTransaction
Private strConnString As String
Public Sub New()
strConnString = System.Configuration.ConfigurationSettings.AppSettings("ConnectionString")
End Sub
Public Function QueryDataReader(ByVal strSQL As String) As MySqlDataReader
Dim dtReader As MySqlDataReader
objConn = New MySqlConnection
With objConn
.ConnectionString = strConnString
.Open()
End With
objCmd = New MySqlCommand(strSQL, objConn)
dtReader = objCmd.ExecuteReader()
Return dtReader '*** Return DataReader ***'
End Function