SelectDB Function

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, the first row of the worksheet and area defined with the name is read as column names for the search and is not used as data.

If multiple tables exist in a single worksheet, the tables in the worksheet cannot be read correctly. Name each table range and specify it as an area defined by name.

Note


  • Connection of PC with installed RC+ is required.

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

SelectDB Example
Using the SQL database

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

Below is a simple example of reading data with an X coordinate greater than 220 in ascending order of Point from the LOGO worksheet in the Excel workbook EPSON_LOGO.xls included in the sample project "DrawEpsonLogo" provided with RC+ 8.0.
For the Excel workbook used in the example, see below.
Sample File

Integer count, i, p, x, y
String desc$

OpenDB #501, Excel, "C:\EpsonRC80\projects\Samples\Database\DrawEpsonLogo\EPSON_LOGO.xls"
count = SelectDB(#501, "[LOGO$]", "X > 220", "Point ASC")
For i = 0 To count - 1
    Input #501, p, x, y, desc$
    Print "Point", p, ", X:", x, ", Y:", y, ", Descripption:", desc$
Next

' Output
'Point 1, X: 224, Y: 51, Descripption:N1
'Point 2, X: 224, Y: 0, Descripption:N2
'Point 11, X: 224, Y: 51, Descripption:N11