Use
This command opens and closes tables and views. It has myriad clauses that let you vary the way it works.
Usage |
USE [ [ Database! ] TableName | [ Database! ] ViewName | ? ] [ IN nWorkArea | cAlias ] [ AGAIN ] [ ONLINE ] [ ADMIN ] [ ALIAS AliasName ] [ NOREQUERY [ nDataSession ] ] [ NODATA ] [ INDEX IndexFileList | ? ] [ ORDER [ nIndex | IDXFileName | [ TAG ] TagName [ OF CDXFileName ] [ ASCENDING | DESCENDING] ] [ EXCLUSIVE | SHARED ] [ NOUPDATE ] [ CONNSTRING cConnectionString ] |
Parameter |
Value |
Meaning |
TableName |
Name |
The name of an existing table to open. Can include a path. If the table is part of an open database, use the long name specified in the database, not the file name. If the name or path includes spaces, enclose it in quotes. |
ViewName |
Name |
The name of an existing view to open. Must either be in the current database or be aliased by the database. If the name includes spaces, enclose it in quotes. |
nWorkArea |
0 |
Open the table in an unused work area. |
Numeric other than 0 |
Open or close the table in the specified work area. |
|
Omitted |
If cAlias is also omitted, open or close the table or view in the current work area. |
|
cAlias |
Character |
Open or close the table or view in the specified work area. |
Omitted |
If nWorkArea is also omitted, open or close the table or view in the current work area. |
|
AliasName |
Name |
The alias to assign the newly opened table or view. |
Omitted |
The alias is the same as the table or view name in most cases. If the table or view name includes spaces, they're changed to underscores in the alias. If the table or view name can't be used as an alias, VFP creates an alias. If the table is opened in one of the first 10 work areas, the alias is one of the letters A through J (with A for work area 1, B for 2, and so on). If the table is opened in any other work area, the alias is the letter W followed by the work area number, such as W1834. |
|
nDataSession |
Numeric |
Used with NOREQUERY, tells the view to get its data from an open copy of the same view in the specified data session. |
IndexFileList |
List of Names |
A comma-separated list of index files to open with the table. |
nIndex |
Numeric |
The position in the index list of the index by which the table should be initially ordered. See CANDIDATE() for a discussion of index numbers. |
IDXFileName |
Name |
The name of the stand-alone index by which the table should be initially ordered. |
TagName |
Name |
The name of the tag by which the table should be initially ordered. |
CDXFileName |
Name |
The name of the compound index file containing TagName. |
cConnectionString |
Character |
An ODBC connection string; pass an empty string to display the SQL Data Source dialog to select a data source. (Views only) |
USE closes any open table in the specified work area before it checks whether it can open the new one. If the open fails, the work area is left with no table open. |
You can close a table without SELECTing its work area first. Just USE IN cAlias to close the table open as cAlias. |
You don't even have to know that a table is open to close it in whatever work area it's open. USE IN SELECT("cAlias") will close the table because SELECT() returns the work area the alias is open in, if it's open, or zero if the table isn't open. USE IN 0 has no effect. MVP Cindy Winegarden showed us this one. |
There are two bugs related to the NODATA clause. The first is that if a view parameter is listed in the AND clause of the JOIN part of a view's SQL SELECT statement, VFP displays the parameter dialog even when the view is opened NODATA. Here's an example of such a view: CREATE SQL VIEW TestView AS ; SELECT * FROM Orders ; JOIN OrdItems ; ON Orders.Order_ID = OrdItems.order_ID and ; Orders.Cust_ID = ?vp_CustID The second bug is similar: The parameter dialog displays when a view that SELECTs from a parameterized view is opened NODATA. In that case, the parameter dialog is for the underlying parameterized view. Although Microsoft claims this behavior is "by design," in our opinion it's a bug; the NODATA clause should be respected in any views the USE command has to open. |
In the initial release of VFP 7, the ALIAS clause was ignored if you used the CONNSTRING clause. This bug was fixed in Service Pack 1. |
Example |
* Open a table in an unused work area in a specified order. USE Employee IN 0 ORDER Last_Name * Open a view. OPEN DATA TasTrade * Quotes are needed below because of embedded blank, so we'll * assign an alias. USE "Product Listing" ALIAS Prods * Create a connection that points to the Northwind Access * database, and create a view on the Orders table. CREATE DATABASE TestConn CREATE CONNECTION NorthWindAccess ; CONNSTRING 'driver=Microsoft Access Driver (*.mdb);' + ; 'dbq=c:\Program Files\Microsoft Visual Studio\VB98\NWind.mdb' CREATE SQL VIEW Orders CONNECTION NorthWindAccess ; AS SELECT * FROM ORDERS USE Orders BROWSE USE * Now open the Orders view but from the SQL Server version of * the Northwind database. USE Orders CONNSTRING 'driver=SQL Server;server=(local);' + ; 'database=northwind;uid=sa;' BROWSE |
See Also |
AfterOpenTable, BeforeOpenTable, Candidate(), CreateOffline(), Create SQL View, NoDataOnLoad, OldVal(), Select, Select(), Set Exclusive, Set Index, Set Order, SQLConnect(), Used() |