Run An Update Query

    Public Function MarkAsAlreadyPacked(ByVal strOrderNum As String) As Boolean
        'Make Required Declarations...
        Dim sql As String
        Dim con As New OleDb.OleDbConnection
        Dim dbprovider As String
        'Dim dbsource As String
        dbprovider = "PROVIDER=Microsoft.jet.OLEDB.4.0;"
        con.ConnectionString = dbprovider & dbsource
        Dim upd As New OleDb.OleDbCommand
        con.Open()
        sql = "UPDATE tblDeliveryAdds SET [AlreadyPacked]=TRUE WHERE OrderNum = '" & strOrderNum & "'"
        Try
            upd = New OleDb.OleDbCommand(sql, con)
            upd.ExecuteNonQuery()
            con.Close()
            upd.Dispose()
            MarkAsAlreadyPacked = True
        Catch ex As Exception
            MarkAsAlreadyPacked = False
            MessageBox.Show("Couldnt Update Order Packed Status..." & Err.Description, "Caution")
            con.Close()
            upd.Dispose()
        End Try
    End Function

 

Retrieve Boolean Value

    Public dbsource = "Data Source =" & System.AppDomain.CurrentDomain.BaseDirectory() & "/dbSales.mdb"


    Public Function IsWorkingDay(strDayName As String) As Boolean
        Dim con As New OleDb.OleDbConnection
        Dim dbprovider As String
        'Dim dbsource As String
        dbprovider = "PROVIDER=Microsoft.jet.OLEDB.4.0;"
        con.ConnectionString = dbprovider & dbsource
        con.Open()
        Dim ds As New DataSet
        Dim da As OleDb.OleDbDataAdapter
        Dim sql As String
        sql = "select * from tblSettings Where DayName = '" & strDayName & "'"
        da = New OleDb.OleDbDataAdapter(sql, con)
        da.Fill(ds, "myData")
        IsWorkingDay = ds.Tables("myData").Rows(0).Item("Working") = True       
        con.Close()
    End Function

 

Save Form Data To Database

    Public Function SaveHealthData() As Boolean
        'Open Database Connection
        Dim sql As String
        Dim con As New OleDb.OleDbConnection
        dbprovider = "PROVIDER=Microsoft.jet.OLEDB.4.0;"
        dbsource = "Data Source =" & System.AppDomain.CurrentDomain.BaseDirectory() & "/Training2020.mdb"
        con.ConnectionString = dbprovider & dbsource
        con.Open()
        'Declare Variables
        Dim intWeight, intHeartSystolic, intHeartDiastolic, intPulseRate, intBloodOxygen, intPalpitations As Integer
        Dim txtHealthNotes As String
        Dim dteSessionDate As Date = Date.ParseExact(Me.txtHealthDate.Text, "dd/MM/yyyy", System.Globalization.DateTimeFormatInfo.InvariantInfo)
        intWeight = Val(Me.txtWeight.Text)
        intHeartSystolic = Val(Me.txtHeartSystolic.Text)
        intHeartDiastolic = Val(Me.txtHeartDiastolic.Text)
        intPulseRate = Val(Me.txtPulseRate.Text)
        intBloodOxygen = Val(Me.txtBloodOxygen.Text)
        txtHealthNotes = Me.txtHealthNotes.Text
        intPalpitations = Me.txtPalpitations.Text
        'Save Data
        Dim upd As New OleDb.OleDbCommand
        Try
            sql = "Insert into tblHealth values ('" & dteSessionDate & "', " & intWeight & ", " & intHeartSystolic & ", " & intHeartDiastolic & ", " & intPulseRate & ", " & intBloodOxygen & ", '" & txtHealthNotes & "', " & intPalpitations & ")"

            upd = New OleDb.OleDbCommand(sql, con)
            upd.ExecuteNonQuery()
            'MessageBox.Show("SAVE SUCCESSFUL", "Update Complete")
            con.Close()
            upd.Dispose()
            SaveHealthData = True
        Catch ex As Exception
            SaveHealthData = False
            MessageBox.Show("SAVE FAILED : " & Err.Description, "Caution")
            MsgBox(Err.Description)
        End Try
    End Function

 

Simple Loop Through Recordset

        Dim con As New OleDb.OleDbConnection
        con.ConnectionString = dbprovider & dbsource
        con.Open()
        Dim ds As New DataSet
        Dim da As OleDb.OleDbDataAdapter
        Dim strSQL As String = "SELECT  tblSessionLog.Duration, tblSessionLog.TrainingType, tblSessionLog.SessionDate FROM tblSessionLog WHERE tblSessionLog.SessionDate >now()-366"
        da = New OleDb.OleDbDataAdapter(strSQL, con)
        da.Fill(ds, "MyData")

        Dim MaxRecCount As Integer
        Dim inc As Integer
        inc = -1
        MaxRecCount = ds.Tables("MyData").Rows.Count

        Dim intStrength, intAerobic As Integer

        For inc = 0 To MaxRecCount - 1

                    intStrength = intStrength + ds.Tables("MyData").Rows(inc).Item("Duration")

        Next

        con.Close()

 

 

SpaceFooter
Website_Design_NetObjects_FusionWeb
 Counter

www.CarlsPlace.co.uk

This Is A United Kingdom Site...