Monday, November 16, 2009

Visual Basic 2005 date format changes to US for ONLY some records?

SELECT * FROM tblbookings WHERE BDate = #13/08/2007#


This SQL query finds records that are dated 13/8/2007 (dd/mm/yyyy)





SELECT * FROM tblbookings WHERE BDate = #12/08/2007#


This SQL query finds records that are dated 8/12/2007 (mm/dd/yyyy)





This happens in the same program, I select a date greater than the 13th of the month and it work correctly.


If I select a date under the13th then, even though the record saves correctly (all dates look fine in the access database), I cannot find it until I change the date to 8/12/2007.


I have all region settings set to austalian date format, etc.


Where can I instruct VB to OleDbDataAdapter to sort the dates in one format? !

Visual Basic 2005 date format changes to US for ONLY some records?
You can use the OleDbParameter in OleDbcommand to avoid this problem...





Dim cmd As New OleDbCommand





cmd.CommandType = CommandType.Text


cmd.CommandText = "SELECT * FROM tblbookings WHERE BDate = @BDate"





cmd.Parameters.Add("@BDate", OleDbType.Date, 0, "BDate")





cmd.Paramters("@BDate").Value = datevalue





adapter.SelectCommand = cmd


No comments:

Post a Comment