Imports System.Data.SqlClient

Public Class CSQLInterface
    Dim m_SqlConn As SqlConnection = Nothing
    Dim m_DTable As New DataTable
    Dim m_BaseName As String = ""
    Public Function ConnectionSetting(ByVal strHostIp As String, ByVal DataBaseName As String, ByVal user As String, ByVal password As String) As Boolean
        If m_SqlConn Is Nothing Then
            m_SqlConn = New SqlConnection
        Else
            m_SqlConn.Close()
        End If

        m_SqlConn.ConnectionString = "server=" & strHostIp & ";database=" & DataBaseName & ";uid=" & user & ";pwd=" & password

        m_BaseName = DataBaseName
        Return (True)
    End Function

    Public Function Query(ByVal strQuery As String, ByRef r_Table As DataTable) As Boolean
        Dim Result As Boolean = False
        Try
            m_SqlConn.Open()
            Dim daAdapter As SqlDataAdapter = New SqlDataAdapter(strQuery, m_SqlConn)
            daAdapter.Fill(r_Table)

            Result = True
        Catch ex As Exception
        End Try

        Try
            m_SqlConn.Close()
        Catch ex As Exception
        End Try

        Return Result
    End Function

    Public Function ExeCommand(ByVal strExe As String) As Boolean
        Dim Result As Boolean = False

        Try
            m_SqlConn.Open()
            Dim myCommand As SqlCommand = New SqlCommand(strExe, m_SqlConn)
            If myCommand.ExecuteNonQuery() > 0 Then
                Result = True
            End If
        Catch ex As Exception
        End Try

        Try
            m_SqlConn.Close()
        Catch ex As Exception
        End Try

        Return Result
    End Function

    'Public Function Insert(ByVal strInsert As String) As Boolean
    '    Return ExeCommand(strInsert)
    'End Function

    'Public Function Update(ByVal strUpdate As String) As Boolean
    '    Return ExeCommand(strUpdate)
    'End Function

    'Public Function Delete(ByVal strDelete As String) As Boolean
    '    Return ExeCommand(strDelete)
    'End Function
End Class
