Imports Microsoft.VisualBasic
Imports System.Data
Imports System.Data.SqlClient
Imports DAL
Namespace DAL
Public Class db
'''
''' Function return connection string with open state
''' '''
'''
Public Function OpenConnection() As SqlConnection
SqlConnection.ClearAllPools()
Dim str As String = ""
str = ConfigurationManager.ConnectionStrings("con").ConnectionString
Dim cn As New SqlConnection
cn.ConnectionString = str
cn.Open()
Return cn
End Function
'''
''' Function use the execute non query
''' '''
'''
'''
Public Sub ExecuteNonQuery(ByVal strQuery As String, Optional ByVal strFunctionName As String = "")
HttpContext.Current.Trace.Warn(strFunctionName & ":" & strQuery)
Dim cn As New SqlConnection
Dim cmd As New SqlCommand
Try
cn = OpenConnection()
cmd.Connection = cn
cmd.CommandType = CommandType.Text
cmd.CommandText = strQuery
cmd.ExecuteNonQuery()
Finally
cn.Close()
End Try
End Sub
'''
''' Function return dataset
''' '''
'''
'''
Public Function FillDataset(ByVal strQuery As String, Optional ByVal strFunctionName As String = "") As DataSet
HttpContext.Current.Trace.Warn(strFunctionName & ":" & strQuery)
Dim cn As New SqlConnection
Dim cmd As New SqlCommand
Dim dst As New DataSet
Dim da As New SqlDataAdapter
Try
cn = OpenConnection()
cmd.Connection = cn
cmd.CommandType = CommandType.Text
cmd.CommandText = strQuery
cmd.ExecuteNonQuery()
da = New SqlDataAdapter(cmd)
da.Fill(dst)
Finally
cn.Close()
End Try
Return dst
End Function
'''
''' Function return dataset
''' '''
'''
'''
Public Function FillDatareader(ByVal strQuery As String, Optional ByVal strFunctionName As String = "") As SqlDataReader
HttpContext.Current.Trace.Warn(strFunctionName & ":" & strQuery)
Dim cn As New SqlConnection
Dim cmd As New SqlCommand
Dim dr As SqlDataReader
cn = OpenConnection()
cmd.Connection = cn
cmd.CommandType = CommandType.Text
cmd.CommandText = strQuery
dr = cmd.ExecuteReader()
Return dr
End Function
End Class
End Namespace