Select count SQL on an access DB Date/Time Column ?

  • Thread starter Thread starter Dart151908
  • Start date Start date
D

Dart151908

Guest
Hi all,

HELP !!!

I am using VB 2010 Express on a MS Access2002 DB.

One of the columns is Date/Time. I have loaded a number of the columns with date and time : "07/01/2016 12:28:15" for testing purposes.

However when I use the following query it returns 0/Zero :


Dim mydate AsDateTime= "07/01/2016 12:28:15"
















Dimcmd2 AsNewOleDbCommand("SELECT COUNT(*) AS mycount FROM [Accidents] WHERE [Adate] = #"& mydate & "# ", myConnection)








Dim count AsInteger= Convert.ToInt32(cmd2.ExecuteScalar())






MsgBox(count)




I have tried "loads" of other ways - some suggested on this site and other forums, but nothing seems to work. Even using the following explicit query only returns 0/zero ?


Dim cmd2 As New OleDbCommand("SELECT COUNT(*) AS mycount FROM [Accidents] WHERE [Adate] = # 07/01/2016 12:28:15 # ", myConnection)



I know that I should use Paramaters/Try etc - and will do so once I know that this "simple" query works.

PS the DB connect string etc all works OK because I use it a lot elsewhere in the App. The query returns no errors.

Geo

Continue reading...
 
Back
Top