473,803 Members | 2,807 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

vb.net - sql statement with "where date ="


Hi,

I've got a problem accessing a ms-access db with a sql statement like
this:

SELECT * FROM laTable WHERE laDate = #05/21/2004# ;
with asp.net (vb code)

laTable contains a "laDate" datetime field .

Request works in ms-access, but not in asp.net,
I get "internal automation error" on line:
OleDbDataAdapt. ExecuteReader()

I can't understand...

If I run a request with a "where" on something other than a date stuff,
it works both in access and asp.

I've tried some other things:
with " ' " => donnees incompatibles dans le critere
with date and time => automation error
with LIKE instead of " = " => automation error

I'm busy with that since now a few days...

thanks for any help

-- yannick --

PS:
config:
access 2000 database / asp.net framework 1.1 / VS.net

code:
requete = "SELECT * FROM laTable WHERE laDate = #05/21/2004#

OleData_prod.Se lectCommand.Con nection = OLE_dataBase
OleData_prod.Se lectCommand.Com mandType = CommandType.Tex t
OleData_prod.Se lectCommand.Com mandText = requete

OleData_prod.Se lectCommand.Con nection.Open()

OleData_prod.Se lectCommand.Exe cuteReader()

OleData_prod.Se lectCommand.Con nection.Close()

OleData_prod.Fi ll(leDataset)

Nov 20 '05
12 27029
I just threw this Windows Forms program together in 2 minutes. It works for
me! (The database I am reading from is in MS Access 97 format)

Private Sub Form1_Load(ByVa l sender As Object, ByVal e As
System.EventArg s) Handles MyBase.Load
Dim cn As OleDb.OleDbConn ection

cn = New OleDbConnection ("Provider=Micr osoft.Jet.OLEDB .4.0;Data
Source=db.mdb")

Dim sql As String
sql = "SELECT * FROM laTable WHERE laDate = @laDate"

Dim cmd As New OleDbCommand(sq l, cn)
cmd.Parameters. Add(New OleDbParameter( "@laDate",
OleDbType.Date) ).Value = New DateTime(2004, 5, 21)

Dim dr As OleDbDataReader
Try
cn.Open()
dr = cmd.ExecuteRead er()

Do While dr.Read
Debug.WriteLine (dr("laDate"))
Loop

Catch ex As Exception
MsgBox(ex.ToStr ing)
Finally
If Not dr Is Nothing AndAlso Not dr.IsClosed Then dr.Close()
cn.Close()
End Try
End Sub

HTH,
Greg

"Yannick" <po****@nowhere .com> wrote in message
news:MP******** *************** *@news.wanadoo. fr...

I get exactly the same error !

I find this really strange. Am I the only one in the universe to get
that vb.net's behaviour ?!

--yannick--

In article <#N************ **@TK2MSFTNGP09 .phx.gbl>, you say...
Try using parameters instead.

Dim cn As New OleDb.OleDbConn ection("Provide r=Microsoft.Jet .OLEDB.4.0;Data Source=" & Server.MapPath( ConfigurationSe ttings.AppSetti ngs("dbPath")))
Dim cmd As New OleDbCommand("S ELECT * FROM laTable WHERE laDate = @laDate", cn)
cmd.Parameters. Add(New OleDbParameter( "@laDate", OleDbType.Date) ).Value = New DateTime(2004, 5, 21)
HTH,
Greg

Nov 20 '05 #11
Yannick,
Have you tried this with just a list of named fields to retrieve vs. * ?
Possibly you have a reserved word for a field name which could be confusing
the OleDb parser. This often causes problems in ADO.NET where the same
query will work in Access. Start with just
Select laDate from laTable WHERE (laDate = #your date here#);
and see if that works.

Ron Allen
"Yannick" <po****@nowhere .com> wrote in message
news:MP******** *************** *@news.wanadoo. fr...

Hi,

I've got a problem accessing a ms-access db with a sql statement like
this:

SELECT * FROM laTable WHERE laDate = #05/21/2004# ;
with asp.net (vb code)

laTable contains a "laDate" datetime field .

Request works in ms-access, but not in asp.net,
I get "internal automation error" on line:
OleDbDataAdapt. ExecuteReader()

I can't understand...

If I run a request with a "where" on something other than a date stuff,
it works both in access and asp.

I've tried some other things:
with " ' " => donnees incompatibles dans le critere
with date and time => automation error
with LIKE instead of " = " => automation error

I'm busy with that since now a few days...

thanks for any help

-- yannick --

PS:
config:
access 2000 database / asp.net framework 1.1 / VS.net

code:
requete = "SELECT * FROM laTable WHERE laDate = #05/21/2004#

OleData_prod.Se lectCommand.Con nection = OLE_dataBase
OleData_prod.Se lectCommand.Com mandType = CommandType.Tex t
OleData_prod.Se lectCommand.Com mandText = requete

OleData_prod.Se lectCommand.Con nection.Open()

OleData_prod.Se lectCommand.Exe cuteReader()

OleData_prod.Se lectCommand.Con nection.Close()

OleData_prod.Fi ll(leDataset)

Nov 20 '05 #12
"Greg Burns" <greg_burns@DON T_SPAM_ME_hotma il.com> wrote in message news:Od******** ******@TK2MSFTN GP12.phx.gbl...
| I just threw this Windows Forms program together in 2 minutes. It works for
| me! (The database I am reading from is in MS Access 97 format)
|
| Private Sub Form1_Load(ByVa l sender As Object, ByVal e As
| System.EventArg s) Handles MyBase.Load
| Dim cn As OleDb.OleDbConn ection
|
| cn = New OleDbConnection ("Provider=Micr osoft.Jet.OLEDB .4.0;Data
| Source=db.mdb")
|
| Dim sql As String
| sql = "SELECT * FROM laTable WHERE laDate = @laDate"
|
| Dim cmd As New OleDbCommand(sq l, cn)
| cmd.Parameters. Add(New OleDbParameter( "@laDate",
| OleDbType.Date) ).Value = New DateTime(2004, 5, 21)
|
| Dim dr As OleDbDataReader
| Try
| cn.Open()
| dr = cmd.ExecuteRead er()
|
| Do While dr.Read
| Debug.WriteLine (dr("laDate"))
| Loop
|
| Catch ex As Exception
| MsgBox(ex.ToStr ing)
| Finally
| If Not dr Is Nothing AndAlso Not dr.IsClosed Then dr.Close()
| cn.Close()
| End Try
| End Sub
|
| HTH,
| Greg

Much better solution than my suggestion.

ChrisG
Nov 20 '05 #13

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
4102
by: Yann GAUTHERON | last post by:
Hi, ID_LOGIN is an integer Can anyone say me if this : WHERE index1=ID_LOGIN OR index2=ID_LOGIN must be slower than those 2 queries :
9
9601
by: Frederik | last post by:
Hi all, I'm building a C# application that uses a M$ Acces database. In one of the queries I use something like the following: SELECT id FROM mytable WHERE id IN (20, 12, 21, 14) The result is fine, except that the order of the id's is not preserved. It seems to be ordered ascending. How can I keep the order I used as input?
1
1687
by: Akhenaten | last post by:
Probably something simple but all email I send via mail() is received with an "unknown date" stamp. Am I missing something in my header? Code as follows: ***************************** <?php $headers = <<<END From: this@email.com Date: $date X-Mailer: PHP v$phpversion
0
2155
by: Curious | last post by:
Hi, I have two columns defined as DateTime type in the Visual Designer, i.e., Dataset.xsd. In the grid to which the columns are bound, they're both displayed as date, for instance, 5/23/2007. It seems that they're using the default "short date" format. I want to use the "long date" format to display the actual hour/minute/
0
1235
by: Curious | last post by:
Hi, I have two columns in a grid defined as DateTime type. Currently, they're both displayed in the format of "5/23/2007", for an example. It seems that they're using the default "short date" format. I want to use the format of, for an example, "5/23/2007 12:35:58 PM", to include hour/minute/second to display one column (while keeping the format of the other column as it is). Anyone can advise me on how to
4
3263
by: Curious | last post by:
Hi, I have a column in a grid defined as DateTime type. Currently, it's displayed in the format of "5/23/2007", for an example. It seems that it's using the default "short date" format. I want to use the format of, for an example, "5/23/2007 12:35:58 PM", to include hour/minute/second. Anyone can advise me on how to change the format?
7
21983
mkremkow
by: mkremkow | last post by:
Hello all, Access 2003 Windows PC: I am trying to figure out why my Query isn't working. In this query, I want to get only those jobs that are still open and where at least one of four Yes/No fields is "Yes". In my query, "Date Closed" field criteria "is null". My result is a listing of all jobs that have at least one of the four Yes/No fields, regardless of close date. Any suggestions? Thanks!
5
2525
by: saddist | last post by:
Hello, I have an access report with WHERE clause: "WHERE tMonth in (Forms!frmMain!txtMonths)" when txtMonths = "7" (f.e.) it works just fine, but when I try to execute the code when txtMonths = "7,8" it displays empty report Any idea what can be wrong?
13
4958
by: Tim Mullin | last post by:
Hello all, I'm hoping to find an answer to a question I have using forms in Access 2007. I have a form (source: table) that has three fields: Start Date Term (number of months) End Date
0
9565
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
1
10295
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10069
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9125
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6844
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5501
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5633
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4275
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
2972
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.