Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
USING SQL
Message
From
01/10/1999 09:43:22
 
 
To
23/09/1999 12:17:28
John Vlahos
V I Software Solutions Design
Mississauga, Ontario, Canada
General information
Forum:
Visual Basic
Category:
Other
Title:
Miscellaneous
Thread ID:
00268046
Message ID:
00271496
Views:
22
>I am trying to write SQL statements within VB, but the VB compiler
>generates an error, stating "Expected: CASE". It assumes I wish to
>use the Select Case statements of VB. I do not. How can I bypass
>this. Is there anything I have to enable or activate before I can
>use the SELECT SQL statement?

John:

You do realize that, unlike Visual FoxPro where you can write and manipulate the databases directly from anywhere in the code, with VB, you need to open and connect to the database you want to use before you can select from it. In other words, it's not like in FoxPro where you can...


USE myTable As a_my Alias SHARED
SELECT * FROM a_myAlias INTO CURSOR


...you have to create a connection to the database....


Dim dbsMyTable As Database
Set dbsMyTable = OpenDatabase("MyTable")


Again, I apologize if you already realize all this. Anyway, after that, you need to open a recordset based on the query that you want to use. I use a variable to create my SQL statement:


sqlQuery = "SELECT * FROM mytalbe WHERE columnname = '"
sqlQuery = sqlQuery & Trim(varCriteria) & "'"


...then I open the recordset based on that query...


Set rstMaster = dbsUnitape.OpenRecordset(sqlQuery, dbOpenDynaset, dbReadOnly, dbReadOnly)


From there, you can manipulate the recordset with that...


rstMaster.MoveLast
recordcnt = rstMaster.RecordCount
rstMaster.MoveFirst

Do While Not rstMaster.EOF

MyData = rstMaster!MyName

Loop

rstMaster.Close
Set rstMaster = Nothing


...a bit lengthy, but I hope that's what you are looking for.

-Joe
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform