I am building an appointment booking system web application in asp.net in VB,
Im simply trying to check whether an appointment has been made on a date selected from the calendar control. I am using Linq for the bindings but the format from the calendar is mmddyyyy when i need ddmmyyyy, my appointments entered int sql table as are 20/09/2012 10:00:00
trying to use a linq from p in db.apps
where p.date=mycontrol.selecteddate
does not yield results
some code added:-
Dim myDate As Date = appCalender.SelectedDate
Dim stat = From a In db.Appointments
Where a.dateAndTime = DateTime.Parse(myDate).ToString("ddMMyyyy")
Select New With {a.dateAndTime}
Dim myList As List(Of String) = Nothing
For Each a In stat
myList.Add(a.dateAndTime)
Next
ListBox1.DataSource = myList
ListBox1.DataBind()
im not sure if the code DateTime.Parse,,,, is right, there are many appoinments on the selected date which i select from the calendar but i think the DateTime format is not translating into SQL correctly
The appointment datatype in SQL is datetime
You aren’t comparing the same datatypes.
If the column in your database (and Linq) is a DateTime, the value on the right of the “=” is a string. It won’t match up. Try this?
EDIT
Also, it looks like you are only getting the Date from your calendar, not the time:
But you say your dates are stored as “20/09/2012 10:00:00”
20/09/2012 10:00:00 != 20/09/2012 00:00:00
Which is probably what is happening.
Try this