I want to compare a date in a database to today's date and it they are equal. Display the contents of the related date in the database in datagridview on a new form.  


This is my code



Private Sub TimerAppoint_Tick(sender As Object, e As EventArgs) Handles TimerAppoint.Tick
        Dim TheDate As String = Now.ToString(" MMMM dd yyyy")
        Dim con As New OleDbConnection
        Dim cmd As New OleDb.OleDbCommand
        cmd = New OleDbCommand(Command, con)

        con.ConnectionString = System.Configuration.ConfigurationManager.AppSettings("Patients")

        Dim dt As New DataTable
        Dim ds As New DataSet
        ds.Tables.Add(dt)
        Dim da As New OleDbDataAdapter("SELECT AppDate AS Expr7 FROM Appointments", con)
        da.Fill(dt)

        For Each DataRow In dt.Rows

            If (TheDate - 1) = (AppDateDateTimePicker.Text = DataRow(0)) Then

                appoint.Show()
                appoint.AppointmentsDataGridView.Show()

                con.Close()
                Return

            End If
        Next
        con.Close()
        Return
    End Sub

i do this with mysql :

Using conn As New MySqlConnection("myConnectionString")
   conn.Open()
   Dim command As New MySqlCommand("SELECT DATE_FORMAT(myDateColumn, '%d-%m-%Y') FROM myTable", conn)
      If command.ExecuteScalar = Format(Date.Now, "dd-MM-yyyy") Then
         MsgBox("this date is equal with now date")
      End If
   command.Dispose()
   conn.Close()
End Using

PS : i format date from mysql side to "14-07-2013", and so with vb side to "14-07-2013"

if you are using mssql then use this query

select field1 , field2 from table1 where table1.DateField = getdate()

Regards.

Im using access database hence i cant use those codes

I hope this small piece of codes can help you in some way:-

01 Protected Sub Calendar1_Selectionchanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles Calendar1.Selectionchanged
02 Label7.Text = Calendar1.SelectedDate().ToShortDateString
03 Calendar1.Visible = True
04 Dim GETDATE As Date
05 If Label7.Text > GETDATE Then
06 Label3.Text = "Please insert a valid date"
07
08
09 End If
10 End Sub

Ref: AllCodingtips.com

try this one

For Each datarow In dt.Rows
    if datenow = datarow.item(1) then   " datarow.item(1) = date in your database 
        Return True                     " indicate function you want
    End If
Next
    Return False
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.