How to retrieve the data by Date/Time Data Type from a Table ?
-
My table has 4 fields that Name, Age, Date and Town. Data can add and delete. Data from Date field are displayed onto the ComboBox by DISTINCT SQL keyword. I wanna retrieve the data from Name, Age and Town by choosing a data from ComboBox that contains date data. I will display my data onto a DataGridView. When I run my project no data display noto the DataGridView. But I get for 18/3/08, error format 12:00:00AM is displayed in Message box and for other date I get correct format. My code is following... Private Sub cbbDate_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles cbbDate.SelectedIndexChanged On Error Resume Next Dim dt As Date cbbDate.Text = cbbDate.SelectedItem If Not cbbDate.Text = "All Date" Then dt = CDate(cbbDate.SelectedItem).ToString("M,d,yyyy") MsgBox(dt) DisplayReport("SELECT * FROM tblSave WHERE Date=" & dt & " ORDER BY Name ASC") Else ShowAll() End If Date Field Format in the table is 'Short Date'. ( month, day, year) Date format from ComboBox is ( day, month, year).
-
My table has 4 fields that Name, Age, Date and Town. Data can add and delete. Data from Date field are displayed onto the ComboBox by DISTINCT SQL keyword. I wanna retrieve the data from Name, Age and Town by choosing a data from ComboBox that contains date data. I will display my data onto a DataGridView. When I run my project no data display noto the DataGridView. But I get for 18/3/08, error format 12:00:00AM is displayed in Message box and for other date I get correct format. My code is following... Private Sub cbbDate_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles cbbDate.SelectedIndexChanged On Error Resume Next Dim dt As Date cbbDate.Text = cbbDate.SelectedItem If Not cbbDate.Text = "All Date" Then dt = CDate(cbbDate.SelectedItem).ToString("M,d,yyyy") MsgBox(dt) DisplayReport("SELECT * FROM tblSave WHERE Date=" & dt & " ORDER BY Name ASC") Else ShowAll() End If Date Field Format in the table is 'Short Date'. ( month, day, year) Date format from ComboBox is ( day, month, year).
phowarso wrote:
But I get for 18/3/08, error format
phowarso wrote:
Date Field Format in the table is 'Short Date'. ( month, day, year) Date format from ComboBox is ( day, month, year).
Well, that's obviously the issue then.
phowarso wrote:
DisplayReport("SELECT * FROM tblSave WHERE Date=" & dt & " ORDER BY Name ASC")
Don't do this. Parameterise your query, then this sort of thing will take care of itself.
Christian Graus - Microsoft MVP - C++ "also I don't think "TranslateOneToTwoBillion OneHundredAndFortySevenMillion FourHundredAndEightyThreeThousand SixHundredAndFortySeven()" is a very good choice for a function name" - SpacixOne ( offering help to someone who really needed it ) ( spaces added for the benefit of people running at < 1280x1024 )