Link to home
Start Free TrialLog in
Avatar of strongd
strongdFlag for United States of America

asked on

Using SQL statement in Visual Basic to query

I have a form, textbox, data control, a DBGrid control, and a command button.  I have the data control connected to a DBASE table, the DBGrid is connected with the data control to display the table in the grid.  I am trying to type the SQL statement into the textbox, then I press a button to query the table.  This isn't working
My table name is  MyTable.DBF
here is my statement
This go's into the textbox

SELECT FirstName
FROM MyTable

Button Code is
Event Click

Data1.RecordSource = Text1.text
Data1.Refresh

When I press my button, VB gets confused.  It doesn't understand.
Here is the message box I get....

Run-Time Error 3125
The database engine can't find "SELECT FirstName FROM MyTable"
Make sure it is a valid parameter or alias name, that it doesn't include invalid character or punctuation and that the name isn't too long.

I have tried quotes around the SQL statement but doesn't work either...
Please someone help.
Thanks
 
Avatar of aeklund
aeklund

Try setting the command type to and make sure to refresh the data:

  Data1.CommandType=adCmdText
  Date1.Refresh
Avatar of strongd

ASKER

Data1.CommandType=adCmdText

Doesn't work.  I get an error "Method not found"  

Which data control are you using...

I tested it with a Microsoft ADO Data Control 6.0 and it works the way I described.

One additional comment... If you use the ADO Data Control 6.0 and the Data Grid 6.0, the example I showed works..
Avatar of strongd

ASKER

I will try it... Be right back...
Avatar of strongd

ASKER

How do you get the ADO data control to connect to a database???
Right click on the control, then goto properties, then use either ODBC, or FILE DSN, or use the build button to create a connection string...
Avatar of strongd

ASKER

Will this control work with DBASE?
It will if you have an ODBC drivers, or and OLE DB provider for DBASE, you must have one of those.
Avatar of Ryan Chong
strongd, ADO is the way to go!

In this link you can find how ADO connect to a DBase database:
http://www.able-consulting.com/ADO_Conn.htm

Hope this helps
What is the Data1.DataSource?
Is it an ADO Data Control, if so have you set the ADO Data Controls RecordSource nproperty to = adCmdText ?
From the text 'Data1.DataSource', i would think that it is a Data Control. A down-grade version of ADO Data Control, which available in default Toolbar.
If you are using a DBGrid and the intrinsic data control, then you are using DAO.  Make sure the Connect Property of the data control is the correct version of Dbase, the DatabaseName Property is the directory of the dbase files you are attempting to query, and that the RecordsetType is either 1-Dynaset or 2-Snapshot.  If the RecordsetType is 0-Table, the query will not work.
Hi strongd,
It appears that you have forgotten this question. I will ask Community Support to close it unless you finalize it within 7 days. I will ask a Community Support Moderator to:

    Accept ryancys's comment(s) as an answer.

strongd, if you think your question was not answered at all or if you need help, just post a new comment here; Community Support will help you.  DO NOT accept this comment as an answer.

EXPERTS: If you disagree with that recommendation, please post an explanatory comment.
==========
DanRollins -- EE database cleanup volunteer
I'm in no way trying to be greedy, but I can see ryancys answer working, but I also see my example working and tested with the correct controls.  We are both saying to use ADO.  Points should be split 50/50
Avatar of strongd

ASKER

It never worked.   I am not sure why either.  And Mircosoft tech support sucks!  I decided to not go with VB and went with DBase 2000.   DBase 2000 works great, plus I don't have to use MS products....

I am not a fan a MS.  I think the company has greating marketing, but to developement in their languages sucks.

ASKER CERTIFIED SOLUTION
Avatar of DanRollins
DanRollins
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of strongd

ASKER

Happy B-Day!!!
Returning points.  If the answers do not work, I don't want future PAQ purchasers to pay 10 points for this.

SpideyMod
Community Support Moderator @Experts Exchange