How to make queries with paremeters

  • Thread starter Thread starter Diego F.
  • Start date Start date
D

Diego F.

Hello. I'm trying to make a queries and I'm having problems.

This one works: SELECT SUM(code) as total FROM table.

It returns a Decimal value that I get with ExecuteScalar().

Now I need to use something like:
SELECT SUM(code) as total FROM table WHERE date = '28/08/2004'. If I try to
execute this one I get an error: Specified cast is not valid. What's wrong
with that?

Other question. How can I put a variable to avoid entering by code the date,
what is not very useful.

Regards,

Diego F.
 
Your date field is apparently set as datetime ... so as the message says,
you are trying to implicitly cast from a string to a date. Try something
like:

Private YourDateVariable as Date
YourDateVariable = CDate("28/08/2004")

SELECT SUM(code) as total FROM table WHERE date = YourDateVariable

Which should also help resolve your second issue.
 
Back
Top