PC Review


Reply
Thread Tools Rate Thread

Simple ado question about parameters

 
 
=?Utf-8?B?U3RldmVu?=
Guest
Posts: n/a
 
      21st May 2004
Hi all,

I'm trying to connect to an access database to return a recordset. the only way i can query the database is using sql statements but i can't seem to pass dates in the sql string. I was wondering if it was possible with parameters.

My code is as follows:

Dim rec As Recordset
Dim cnn As New ADODB.Connection
Dim cmd As New ADODB.Command

cnn.CursorLocation = adUseClient
cnn.Open sConnection
cmd.ActiveConnection = cnn
cmd.CommandText = sSQL

sSQL = "select Format(Date_Time, 'dd-mmm-yyyy hh:mm') as When, Format(" & sUnit & "," & sFormat
sSQL = sSQL & ") as Reading from " & Range("DataTable")

-- the dates are on this line as sDate1 and 2, they are stored as strings at the moment..
sSQL = sSQL & " where (Date_Time between '" & sDate1 & "' and '" & sDate2 & "')"
sSQL = sSQL & " and (Format(" & sUnit & "," & sFormat & ") < " & "'" & Range("SpecifiedMin") & "'"
sSQL = sSQL & " or Format(" & sUnit & "," & sFormat & ") > " & "'" & Range("SpecifiedMax") & "'"
sSQL = sSQL & ") order by Date_Time"

Set rec = cmd.Execute

Thanks for any help,
Regards.
Steven
 
Reply With Quote
 
 
 
 
Jon Skeet [C# MVP]
Guest
Posts: n/a
 
      21st May 2004
Steven <(E-Mail Removed)> wrote:
> I'm trying to connect to an access database to return a recordset.
> the only way i can query the database is using sql statements but i
> can't seem to pass dates in the sql string. I was wondering if it was
> possible with parameters.


Yes, it is. See http://www.pobox.com/~skeet/csharp/faq/#db.parameters

--
Jon Skeet - <(E-Mail Removed)>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
 
Reply With Quote
 
Cor Ligthert
Guest
Posts: n/a
 
      21st May 2004
> Steven <(E-Mail Removed)> wrote:
> > I'm trying to connect to an access database to return a recordset.
> > the only way i can query the database is using sql statements but i
> > can't seem to pass dates in the sql string. I was wondering if it was
> > possible with parameters.

>
> Yes, it is. See http://www.pobox.com/~skeet/csharp/faq/#db.parameters
>

Why? It's an ADO question.

I could not find anything about a recordset on that page.

:-)

Cor


 
Reply With Quote
 
Cor Ligthert
Guest
Posts: n/a
 
      22nd May 2004
Hi Steven,

One of the normal regulars from this newsgroup has an article on the MSDN
frontpage. (He is a while not that active as normally, maybe he was to busy
with that article) :-)

Don't be afraid I show you ADONET, because Bill is also describing the
differences from the ADO classic parameter and the ADONET parameter. And
there you have your answer in my opinion.

http://msdn.microsoft.com/data/defau...l/adocnet4.asp

I hope this helps?

Cor


 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
simple one on out parameters in functions =?Utf-8?B?V2ViQnVpbGRlcjQ1MQ==?= Microsoft C# .NET 3 6th Sep 2007 05:12 PM
Simple MS Query with Data Parameters Not Auto-refreshing j.slaughter@mfs.misys.co.uk Microsoft Excel Misc 0 14th Mar 2007 04:00 PM
How to pass simple parameters to a page JezB Microsoft ASP .NET 3 21st Jun 2004 10:39 AM
Simple question ..passing web parameters in the url G.Esmeijer Microsoft C# .NET 1 5th Apr 2004 11:49 PM
Simple Question: Windows Service Parameters Scott Microsoft C# .NET 1 7th Jan 2004 10:45 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 12:05 AM.