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 Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Simple SQL not working !

Status
Not open for further replies.

cbsm

Programmer
Oct 3, 2002
229
FR
Hi !
I am probably missing something very obvious here - but for now, I am just becoming crazy !
I am working on a VB6 application - talking to an Access2000 database.
I am used to this kind of application.
I worked with this specific one for about 1 year - wiht no trouble in this kind.
I've created a query in access (did this to simplify my code). This query (QUERY1) is made of 9 tables.
I am selecting a few field of those tables.
When I run this query in access - I get 1 record as a result - which is OK.
Now - when I run the query from VB - I get 0 record !
(the query is "select * from QUERY1" - no WHERE clause or other)
I checked - I typed in the correct queryname, I am talking the correct DB ...
I added a MSFlexgrid linked to a Data Object - the record is there !
This is how I run the query :
dim rs as adodb.recordset
set rs=new adodb.recordset
set rs=RunQuery("select * from query1")

function Runquery (strSQL as string) as adodb.recordset
Dim RS As ADODB.Recordset
Dim cmd As ADODB.Command
On Error GoTo ErrorHandler
Set RS = New ADODB.Recordset
Set cmd = New ADODB.Command
cmd.ActiveConnection = cnn1 'cnn1 is set at start of application
cmd.CommandText = strSQl
Set RS = New ADODB.Recordset
RS.CursorType = adOpenStatic
RS.LockType = adLockReadOnly
RS.Open cmd
Set RunSQLReturnRORS1 = RS
Set cmd = Nothing
Set RS = Nothing
Exit Function

I run queries this way since the beginning and NEVER had a problem ...
I am sure it is some stupid thing ...

 
My guess is that the query that exists in Access contains a LIKE clause using an "*". To execute the query from VB you will need to have a version that uses an "%" in the like clause.
 
At last ! I got it right !!!
Should have tried this long ago ...
In the query in Access i am using a LIKE "ab*".
Problem is, for VB, the wildchar is a % !!!!
What a waist of time ! Can't they all just use the same ?!
 
>>for VB, the wildchar is a %

that is actually a specification of ADO.
 
% is the standard. Uncle Bill (Gates) likes to do his own thing

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top