problem querying MS Access date/time field in vb.NET

problem querying MS Access date/time field in vb.NET

Post by fforema » Fri, 02 May 2003 01:20:54



I am querying an MS Access data/time field from VB.NET, using
Microsoft.Jet.OLEDB.4.0, and get the following error:

An unhandled exception of type 'System.Data.OleDb.OleDbException'
occurred in system.data.dll

Here is a snippet from my code:

__________________________________
Dim strStartDate, strEndDate As String
strStartDate = Me.StartDateTimePicker.Value.ToString("M/d/yyyy h:mm:ss")
strEndDate = Me.EndDateTimePicker.Value.ToString("M/d/yyyy h:mm:ss")

ChangeDataAdapter.SelectCommand.CommandText = _
"SELECT ch_ticket_id, ch_made_by, ch_made_on, ch_cost,
ch_description " & _
"FROM pt6bt_ti_change " & _
"WHERE ch_cost > 0" & _
" AND ch_made_on >= " & "'" & strStartDate & "'" & _
" AND ch_made_on <= " & "'" & strEndDate & "'"
ChangeDataSet.Clear()
ChangeDataAdapter.Fill(ChangeDataSet, "pt6bt_ti_change")
ChangeDataGrid.SetDataBinding(ChangeDataSet, "pt6bt_ti_change")
_________________________________________

This code works IF I change the date field in the database to a text
field, but does NOT work if the date field in the database is a
date/time field. And I have tried using a Date variable in VB instead of
a String variable; same result.

Thanks in advance

--
Posted via http://dbforums.com

 
 
 

problem querying MS Access date/time field in vb.NET

Post by Sukesh Hooga » Fri, 02 May 2003 02:11:11


Have you tried enclosing the data values in # signs
" AND ch_made_on >= #" & strStartDate & "# .........

--
Regards

Sukesh Hoogan

http://personal.vsnl.com/sukesh_hoogan


Quote:

> I am querying an MS Access data/time field from VB.NET, using
> Microsoft.Jet.OLEDB.4.0, and get the following error:

> An unhandled exception of type 'System.Data.OleDb.OleDbException'
> occurred in system.data.dll

> Here is a snippet from my code:

> __________________________________
> Dim strStartDate, strEndDate As String
> strStartDate = Me.StartDateTimePicker.Value.ToString("M/d/yyyy h:mm:ss")
> strEndDate = Me.EndDateTimePicker.Value.ToString("M/d/yyyy h:mm:ss")

> ChangeDataAdapter.SelectCommand.CommandText = _
> "SELECT ch_ticket_id, ch_made_by, ch_made_on, ch_cost,
> ch_description " & _
> "FROM pt6bt_ti_change " & _
> "WHERE ch_cost > 0" & _
> " AND ch_made_on >= " & "'" & strStartDate & "'" & _
> " AND ch_made_on <= " & "'" & strEndDate & "'"
> ChangeDataSet.Clear()
> ChangeDataAdapter.Fill(ChangeDataSet, "pt6bt_ti_change")
> ChangeDataGrid.SetDataBinding(ChangeDataSet, "pt6bt_ti_change")
> _________________________________________

> This code works IF I change the date field in the database to a text
> field, but does NOT work if the date field in the database is a
> date/time field. And I have tried using a Date variable in VB instead of
> a String variable; same result.

> Thanks in advance

> --
> Posted via http://dbforums.com

---
Outgoing mail is certified Virus Free.
Checked by AVG anti-virus system (http://www.grisoft.com).
Version: 6.0.476 / Virus Database: 273 - Release Date: 24/04/2003

 
 
 

problem querying MS Access date/time field in vb.NET

Post by fforema » Fri, 02 May 2003 03:56:36


Sukesh,

That did the trick! I've never used a '#' in a SQL statement, and don't
really understand what it does, but I'll read up on it. And I thank you
for your help.

frank

--
Posted via http://dbforums.com

 
 
 

1. Query datetime-field by date when field contains date + time

I have tablefield (sqlserver2000) which datatype is datetime. I have
inserted value "insert into ... datetimefield = {ts '2001-11-24
08:24:12'}..." in it. How can I find (query) that row by date ?

I have tried :
... where datetimefield like {d '2001-11-24'}...
... where datetimefield = {d '2001-11-24'}...
... where datetimefield like {d '2001-11-24%'}...
... where datetimefield like {d '%2001-11-24%'}...

..but query never returns that row. Whats wrong ?!?!

This works :
... where datetimefield = {ts '2001-11-24 08:24:12'}...
but time is unknown in "real life".

Connectionstring  is like:
"Provider=SQLOLEDB;Data Source=SERVERNAME;Initial
Catalog=tempdbase;User Id=sa;Password="

And same problem in  access database ?
... where datetimefield = #11/24/2001#...
... where datetimefield like #11/24/2001#...

Maybe its better to use string-datatype instead datetime...

Jaska

2. Datetime conversion problem

3. ADO with Access Date/Time field not storing the time, just the date

4. LightShip compared to...

5. Insert date and time field into MS Access with SQL

6. Master /Detail Forms and other Q

7. MS Access Date/Time field - American/English

8. How to:Job on server kicks off job on other server?

9. MS Access + Delphi Date/Time conversion problems

10. Problem accessing record from SQL Data base Date/Time Field

11. Can't read time from Access 2000 date/time field

12. Problems with Access 2000 and Date/Time fields

13. date/time field query from access97 query