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
ZIPB
0
Newbie Poster
Recommended Answers
Jump to Posti 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 …
Jump to Postif you are using mssql then use this query
select field1 , field2 from table1 where table1.DateField = getdate()
Regards.
All 5 Replies
artemix22
4
Newbie Poster
M.Waqas Aslam
67
Posting Pro in Training
Featured Poster
ZIPB
0
Newbie Poster
RH-Calvin
-2
Junior Poster in Training
shann_
0
Newbie Poster
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.