VB:
Data Object for DataBase
Imports Microsoft.VisualBasic
Imports MySql.Data.MySqlClient
Imports System.Data
Public Module MySqlDbConnCls
Public Function getConnection() As MySqlConnection
Dim MySqlConnStr As String = ConfigurationManager.ConnectionStrings("ConnectionString").ConnectionString
Return New MySqlConnection(MySqlConnStr)
End Function
Public Function Exec_MySql_Query(ByVal query As String) As DataSet
Try
Dim con As MySqlConnection = getConnection()
con.Open()
Dim da As New MySqlDataAdapter(query, con)
Dim ds As New DataSet
da.Fill(ds, "tab1")
con.Close()
Return ds
Catch ex As Exception
Throw
End Try
End Function
Public Function Exec_MySql_NonQuery(ByVal query As String) As Integer
Try
Dim con As MySqlConnection = getConnection()
con.Open()
Dim result As Integer = 0
Dim cmd As New MySqlCommand(query, con)
result = cmd.ExecuteNonQuery()
con.Close()
Return result
Catch ex As Exception
Throw
End Try
Return -1
End Function
Public Function Exec_MySql_Scalar(ByVal query As String) As Object
Try
Dim con As MySqlConnection = getConnection()
con.Open()
Dim result As Object
Dim cmd As New MySqlCommand(query, con)
result = cmd.ExecuteScalar
con.Close()
Return result
Catch ex As Exception
Throw
End Try
Return (New Object)
End Function
End Module
Data Object for DataBase
Imports Microsoft.VisualBasic
Imports MySql.Data.MySqlClient
Imports System.Data
Public Module MySqlDbConnCls
Public Function getConnection() As MySqlConnection
Dim MySqlConnStr As String = ConfigurationManager.ConnectionStrings("ConnectionString").ConnectionString
Return New MySqlConnection(MySqlConnStr)
End Function
Public Function Exec_MySql_Query(ByVal query As String) As DataSet
Try
Dim con As MySqlConnection = getConnection()
con.Open()
Dim da As New MySqlDataAdapter(query, con)
Dim ds As New DataSet
da.Fill(ds, "tab1")
con.Close()
Return ds
Catch ex As Exception
Throw
End Try
End Function
Public Function Exec_MySql_NonQuery(ByVal query As String) As Integer
Try
Dim con As MySqlConnection = getConnection()
con.Open()
Dim result As Integer = 0
Dim cmd As New MySqlCommand(query, con)
result = cmd.ExecuteNonQuery()
con.Close()
Return result
Catch ex As Exception
Throw
End Try
Return -1
End Function
Public Function Exec_MySql_Scalar(ByVal query As String) As Object
Try
Dim con As MySqlConnection = getConnection()
con.Open()
Dim result As Object
Dim cmd As New MySqlCommand(query, con)
result = cmd.ExecuteScalar
con.Close()
Return result
Catch ex As Exception
Throw
End Try
Return (New Object)
End Function
End Module
Comments
Post a Comment