Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Prepared Query Parameters

Status
Not open for further replies.

dirksm

Programmer
Mar 14, 2002
22
0
0
GB
Hi All.

I've got a VB6 program in which I use a adodb.command object to create a prepared query. This query uses parameters, i.e "where company_no=?". Later in my program I give a value to this parameter, i.e "command1.parameters(0)="1234". All of this works fine, until a pass a date as a parameter to a date field in my database. I've tried passing the date as a string, with or without quotes and in different formats (dd/mm/yyyy, mm/dd/yyyy, etc.), but I can't seem to get it to work.

Does anybody know what I'm doing wrong?

I'm using DB2, but I've found that there is little or no difference between the different databases when writing VB code, so help pertaining to any db would be appreciated.
 
You know that there is enough difference between databases to cause problems. For example the "Access" database treats date fields differently from all other databases in that the date field in the query would be surrounded by number signs (#date#) and in other database programs its treated as a string and surrounded by single quotes ('date'). This might be why you are having problems with your query.
 
No, that's not it.

I think I have really tried every possible combination of date formats and also tried quotes, no quotes, hashes, etc.

Here's the code where I set the parameters:
comUpdate.Parameters(0) = "Y"
comUpdate.Parameters(1) = "FIELD2"
comUpdate.Parameters(2) = "FIELD3"
comUpdate.Parameters(3) = "FIELD4"
comUpdate.Parameters(4) = "FIELD5"
comUpdate.Parameters(5) = "FIELDDESREWRTRET6"
comUpdate.Parameters(6) = "FIELD7"
comUpdate.Parameters(7) = "FIELD8"
comUpdate.Parameters(8) = " 'comUpdate.Parameters(9) = "08/12/2002"

The error I get actually says "Wrong number of parameters", but I'm 100% sure that I've got the right number of parameters.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top