lopDAL
Imports System.data.sqlclient
Public Class DAL
Private con As SqlConnection
Private dap As SqlDataAdapter
Private cmd As SqlCommand
Private str As String
Public Sub New()
str = My.Settings.Setting
End Sub
Public Sub New(ByVal _str)
str = _str
End Sub
'mo ket noi
Public Sub moketnoi()
con = New SqlConnection(str)
If con.State <> ConnectionState.Open Then
con.Open()
End If
End Sub
'dong ket noi
Public Sub dongketnoi()
con = New SqlConnection(str)
If con.State <> ConnectionState.Closed Then
con.Close()
End If
End Sub
'lay du lieu tu csdl len dataset
Public Function layDl(ByVal sql As String) As DataSet
Dim ds As New DataSet
Try
moketnoi()
dap = New SqlDataAdapter(sql, con)
dap.Fill(ds)
Catch ex As Exception
Throw New Exception(ex.Message)
Finally
dongketnoi()
End Try
Return ds
End Function
'thuc hien cau truy van den csdl
Public Sub thuchien(ByVal sql As String)
Try
moketnoi()
cmd = New SqlCommand(sql, con)
cmd.ExecuteNonQuery()
Catch ex As Exception
Throw New Exception(ex.Message)
Finally
dongketnoi()
End Try
End Sub
End Class
Bạn đang đọc truyện trên: Truyen247.Pro