Click here to Skip to main content
15,886,258 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
This is the part that I dont know the syntax
I want that my form automatically loads the data from the Database
by using the b_date but only display the records if there is a match in month and date
not using the year, The program is like a Birthday Reminder




VB
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        'TODO: This line of code loads data into the 'Bene_dbDataSet.bene_records' table. You can move, or remove it, as needed.
        Me.Bene_recordsTableAdapter.Fill(Me.Bene_dbDataSet.bene_records)

        con = New OleDb.OleDbConnection
        dbProvider = "Provider=Microsoft.Jet.OLEDB.4.0;"
        dbSource = "Data Source = C:\Users\RedemptorisMater\Desktop\S\K..\WindowsApplication1\WindowsApplication1\bene_db.mdb"

        If Not con.State = ConnectionState.Open Then
            con.Open()
        End If

        Dim da As OleDb.OleDbDataAdapter
        Dim Sql As String

        ''THIS IS THE PART THAT I DONT KNOW THE SYNTAX,
        ''I want that my form automatically loads the data from the Database
        ''by using the b_date but only display the records if theres a match in month and date
        ''not using the year, The program is like a Birthday Reminder
        Sql = "SELECT * FROM bene_records"
        da = New OleDb.OleDbDataAdapter(Sql, con)

        Dim dt As New DataTable
        da.Fill(dt)

        con.Close()

    End Sub
Posted

Please, read my comment to the solution 1

I'd suggest query like this:
SQL
PARAMETERS [mnth] INT;
SELECT <FieldList>
FROM bene_records
WHERE b_date BETWEEN #DateSerial(Year(Date()), [mnth], 1)# AND #DateSerial(Year(Date()), [mnth]+1, 1-1)# 


Above query should return data for given month (from first to last day).
Replace <FieldList> with set of columns you want to return. Do not use * together with SELECT statement, if you care about performance.

To call this, you need to set OledbParameter[^] for OledbCommand[^].

More:
DateSerial (MS Access query)[^]
Data Types (MS Access)[^]
 
Share this answer
 
v3
Comments
Member 11194404 31-Oct-14 8:54am    
is this right?

Sql = "SELECT f_name, m_name, l_name, b_date, home_num, cell_num, addr FROM bene_records WHERE b_date between #DateSerial(Year(Date()), [mnth], 1)# AND #DateSerial(Year(Date()), [mnth]+1, 1-1)#"
da = New OleDb.OleDbDataAdapter(Sql, con)

Dim dt As New DataTable
da.Fill(dt)

con.Close()
Maciej Los 31-Oct-14 8:56am    
No. Please use entire query body.
Member 11194404 31-Oct-14 9:00am    
please enlighten me.. kinda really new on this coding stuff... =/
Maciej Los 31-Oct-14 9:04am    
2 errors:
1) You missed PARAMETERS...,
2) A parameter for OleDbCommand hasn't been specified!
Please, read my answer carefully...
Member 11194404 31-Oct-14 9:21am    
is there any simple code just to fill the DataTableAdapter with the records of those who have equal to the date (Month and Date only) with the Month and Date of the PC.. excluding the year.. coz its like a birthday reminder program
Try:
SQL
SELECT * FROM bene_records WHERE DATEPART(mm, GETDATE()) = DATEPART(mm, dateColumn) AND DATEPART(dd, GETDATE()) = DATEPART(dd, dateColumn)
 
Share this answer
 
Comments
Member 11194404 31-Oct-14 3:57am    
i tried this but there was error (Syntax error in FROM clause.)

Sql = "SELECT * FROM bene_records DATEPART(mm, GETDATE()) = DATEPART(mm, b_date) and DATEPART(dd, GETDATE()) = DATEPART(dd, dateColumn)"
da = New OleDb.OleDbDataAdapter(Sql, con)

Dim dt As New DataTable
da.Fill(dt)
Maciej Los 31-Oct-14 4:09am    
MS Access does not know GETDATE() function!

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900