Imports System.Data.SqlClient

Public Class CDB
    Private m_strConn As String
    Private m_con As SqlConnection

    Public Sub New(ByVal strPath As String)
        m_con = New SqlConnection(strPath)
        m_con.Open()
    End Sub

    Public Sub close()
        m_con.Close()
    End Sub

    Public Function ExecuteNonQuery(ByVal strCmd As String) As Integer
        Dim cmd As SqlCommand = New SqlCommand(strCmd, m_con)
        Return cmd.ExecuteNonQuery()
    End Function

    Public Function ExecuteReader(ByVal strCmd As String) As SqlDataReader
        Dim cmd As SqlCommand = New SqlCommand(strCmd, m_con)
        Return cmd.ExecuteReader
    End Function

    Public Function ExecuteScalar(ByVal strCmd As String) As Object
        Dim cmd As SqlCommand = New SqlCommand(strCmd, m_con)
        Return cmd.ExecuteScalar()
    End Function

    Public Function GetDataView(ByVal strCmd As String, ByVal strTableName As String) As DataView
        Dim adpt As SqlDataAdapter = New SqlDataAdapter
        adpt.SelectCommand = New SqlCommand(strCmd, m_con)
        Dim ds As DataSet = New DataSet()
        adpt.Fill(ds, strTableName)
        Dim dv As DataView = New DataView(ds.Tables(strTableName))
        Return dv
    End Function

    Public Function GetDataTable(ByVal strCmd As String) As DataTable
        Dim adpt As SqlDataAdapter = New SqlDataAdapter(strCmd, m_con)
        Dim ds As DataSet = New DataSet()
        Dim dt As DataTable = ds.Tables.Add("strTableName")
        adpt.Fill(ds, "strTableName")
        Return dt
    End Function
End Class