Discussion Locked

Passing VB6.0 Text into Sql 7 Query

0 helpful
8 replies
Closed to new repliesThis discussion is closed. It stays readable, but it takes no new replies.

I am trying to query a sql database in wich the user enters a date range in a text box and the the query uses this info to parse out
the information using that date range...

Im not having much luck...
would aprecciate any help

8 replies

by sheryl v

Are you using 2 text boxes(e.g., txtStart & txtEnd)?
If so are you forcing "#" at the beginning and end of each date?

Where myDate >= "#" & txtStart & "#" and myDate <= "#" & txtEnd & "#"
Hope this helps.

by fullofhope

I needed to be more Specific in my question I can't seem to pass any Parameter into the sql statement. I keep getting invalid field.
so I need the proper syntax ...
IE...
SELECT * FROM datatable
WHERE blank = textbox

by fullofhope

I should have phrased the question better I need to know the proper syntax for passing parameters into the sql statement I keep getting invalid colum or field name when I try..

select * from datasource where
tr_date > sdate

sdate being a txtbox.

by sheryl v

I think that SQL can not tell that sdate is a date field so instead of:

select * from datasource where
tr_date > sdate

You may need to qualify it:

select * from datasource where
tr_date > "#" & sdate & "#"

Let me know if it works out.

by roc180

Use the following syntax:

strSQL="SELECT * FROM datasource
WHERE tr_date = '"& sdate &"' ;"

strSQL is a string variable that contains your query. Other things to make sure you are doing correctly:
1.Make sure tr_date is the actual nameof your field in the SQL Server table datasource.
2. When using dates in SQL Server enclose the dates with (' ').
3. Whatever your using to execute the query (Recordset,Command Object, etc..) make sure it can see the SQL Server table.

If you are still getting an error send me your blurb of code and I can take a look at it.

Good Luck

Neal Martinelli

This discussion is closed to new replies.