Imports System.Data.OleDb
Imports System.IO
Imports System.Drawing
Imports System.Runtime.InteropServices

Module Module1


    'Public idno, mno As Integer
    Public MyProgress As Integer
    Public idno As Integer = 0 'picture
    Public img As System.Drawing.Image
    Public blnAdd As Boolean 'indicator if add button was pressed
    'Public blnUpdate As Boolean 'indicator if update button was pressed
    Public conn As OleDbConnection
    Public cmd As OleDbCommand
    Public dr As OleDbDataReader
    Public str As String
    Public cn = ("Provider = Microsoft.Jet.OLEDB.4.0;Data Source=C:\Gym\Gym.mdb")
    Public Const cnString As String = "Provider=Microsoft.Jet.OLEDB.4.0;Persist Security Info=False;Data Source=C:\Gym\Gym.mdb"
    Public da As New OleDbDataAdapter '("Select * from tblTransaction", conn)
    Public ds As New DataSet
    Public dt As DataTable
    Public dv As DataView
    <DllImport("user32.dll", SetLastError:=True, CharSet:=CharSet.Auto)> _
    Public Function SetParent(ByVal hWndChild As IntPtr, ByVal hWndNewParent As IntPtr) As IntPtr
    End Function


    Public Enum FormState
        adStateAddMode = 0
        adStateEditMode = 1
    End Enum


    'Fill ListView control with data
    Public Sub FillListView(ByRef lvList As ListView, ByRef myData As OleDbDataReader)
        Dim itmListItem As ListViewItem

        Dim strValue As String

        Do While myData.Read
            itmListItem = New ListViewItem()
            strValue = IIf(myData.IsDBNull(0), "", myData.GetValue(0))
            itmListItem.Text = strValue

            For shtCntr = 1 To myData.FieldCount() - 1
                If myData.IsDBNull(shtCntr) Then
                    itmListItem.SubItems.Add("")
                Else
                    itmListItem.SubItems.Add(myData.GetString(shtCntr))
                End If
            Next shtCntr

            lvList.Items.Add(itmListItem)
        Loop
    End Sub

    Public Function GetData(ByVal sSQL As String)
        Dim connection As OleDbConnection
        Dim sqlCmd As OleDbCommand = New OleDbCommand(sSQL)
        Dim myData As OleDbDataReader

        connection = New OleDbConnection(cnString)

        Try
            connection.Open()

            sqlCmd.Connection = connection

            myData = sqlCmd.ExecuteReader

            Return myData
        Catch ex As Exception
            Return ex
        End Try
    End Function

End Module

