SelectDB Statement

Searches the data in the table in an opened database.

Syntax
SelectDB (#fileNumber, TableName, SelectCondition, SortMethod)

Parameters

fileNumber
Specify the database number (integer value from 501 to 508) specified in OpenDB.
TableName
Table name you want to search in. If the database type specified with #fileNumber is an Excel workbook, specify an Excel worksheet or named table. When specifying an Excel sheet, add $ to end of the worksheet name and enclose the name with [ ]. When specifying an area with a name in an Excel worksheet, enclose the name with [ ].
SelectCondition
Specify the search condition. AND, OR are available to specify the multiple conditions. If omitted, the all data in the table is searched.
SortMethod
Order to show searched data. Specify Sort key and Sort order (ascending order [ASC] / descending order [DESC]). If the Sort order is omitted, the ascending Sort key order is specified. If the SortMethod is omitted, the order is decided by the opened database.

Return Values
Returns total numbers of lines.

Description
Sorts the data which meets the SelectCondition in the specified table of the opened database based on the Sort conditions.

You should execute SelectDB before reading / writing data with the Input# and Print# statements.

If the opened database is an Excel workbook, write a row name to use for the search in the first line of the worksheet and area defined with the name.

For Excel 2007 workbook, the worksheet name must be specified. You cannot access to area defined with the name.

Note


  • Connection of PC with installed RC+ is required.

See Also
OpenDB, CloseDB, UpdateDB, DeleteDB, Input #, Print #

SelectDB Example

The following example uses the SQL server 2000 sample database, Northwind. The Employees table is searched with the condition TitleOfCourtesy = Ms. with EmployeeID in descending order.

  Integer count, i, eid
  String Lastname$, Firstname$, Title$

  OpenDB #501, SQL, "(LOCAL)", "Northwind"
  count = SelectDB(#501, "Employees", "TitleOfCourtesy = 'Ms.'", "EmployeeID DESC")
  For i = 0 To count - 1
    Input #501, eid, Lastname$, Firstname$, Title$
    Print eid, ",", Lastname$, ",", Firstname$, ",", Title$
  Next
  CloseDB #501

Using Access database

The following example uses Microsoft Access 2007 sample database “Students” and loads the data whose ID is more than 10 from the table “Students” in the ID descending order.

  Integer count, i, eid
  String Lastname$, Firstname$, dummy$

  OpenDB #502, Access, "c:\MyDataBase\Students.accdb"
  count = SelectDB(#502, "Students", "ID > 10'", "ID")
  For i = 0 To count - 1
    Input #502, eid, dummy$, dummy$, Lastname$, dummy$, Firstname$
    Print eid, ",", Lastname$, ",", Firstname$
  Next
  CloseDB #502

Using Excel workbook

The following example uses Microsoft Excel workbook “Students“ and loads the data in worksheet “Student” whose Age is under 25 with the ID in ascending order.

  Integer count, i, eid
  String Lastname$, Firstname$

  OpenDB #503, Excel, "c:\MyDataBase\Students.xls"
  count = SelectDB(#503, "[Students$]", "Age < 25", "ID ASC")
  For i = 0 To count - 1
    Input #503, eid, Lastname$, Firstname$
    Print eid, ",", Lastname$, ",", Firstname$
  Next
  CloseDB #503