OpenDB Statement
Opens a database or Excel workbook.
Syntax
OpenDB #fileNumber, { SQL | Accel | Eccel } [, DBserverName As String ],
Parameters
- fileNumber
- Specify an integer from 501 to 508.
- SQL | Accel | Eccel
- Select a database type you want to open from [SQL], [Access], and [Excel].
- DBserverName
- If you select [SQL], the SQL server name is specified. If omitted, LOCAL server is specified. The SQL server on the network cannot be specified.
If you select [Access] or [Excel], the SQL server name is not specified. - DBname
-
- If you select [SQL] as a database, a database name on the SQL server is specified.
- If you select [Access], Access file name is specified. If omitted the path of Access file name, it searches in the current folder. See ChDisk for the details.
- If you select [Excel], Excel file name is specified. You can specify Excel 2007 book or Excel 97-2003 book file as Excel file. If you omitted Excel file name, it searches in the current folder. See ChDisk for the details.
Description
Opens the specified database using the specified file number.
The specified database must exist on the disk of PC with installed RC+. Otherwise, it causes an error. The specified file number can be used to identify the database while it is open, but cannot be used to refer to the different database until you close the database with the CloseDB command. The file number is used with the database operation commands (SelectDB, Print#, Input#, CloseDB).
Access and Excel files of Microsoft office 2010 64-bit cannot be used.
Note
- Connection of PC with installed RC+ is required.
See Also
SelectDB,CloseDB,UpdateDB,DeleteDB,Input #, Print #
OpenDB Statement Example
Using the SQL database
The following example uses the SQL server 2000 sample database, Northwind and loads the data from a table.
Integer count, i, eid
String Lastname$, Firstname$, Title$
OpenDB #501, SQL, "(LOCAL)", "Northwind"
count = SelectDB(#501, "Employees")
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 from a table.
Integer count, i, eid
String Lastname$, Firstname$, dummy$
OpenDB #502, Access, "c:\MyDataBase\Students.accdb"
count = SelectDB(#502, "Students")
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 “StudentsList“ and loads the data from a sheet.
Integer count, i, eid
String Lastname$, Firstname$
OpenDB #503, Excel, "c:\MyDataBase\Students.xls"
count = SelectDB(#503, "[Students$]")
For i = 0 To count - 1
Input #503, eid, Lastname$, Firstname$
Print eid, ",", Lastname$, ",", Firstname$
Next
CloseDB #503