Visual Basic's database programming
Visual Basic's development "tool" as an application is also manifested in the development of database applications, and its good interface and powerful control functions make database programming simpler. But even if so, the development of the database application is still difficult in VB programming, because you are not only familiar with the knowledge of database programming in VB (of course, this is very simple) also understands the knowledge of the database. So let's introduce the basic knowledge of the database, just learn the warm-up exercise before the database programming! First, warm-up exercise first needs to state that the database knowledge we introduced here refers to the relational database. The so-called relational database is to represent a collection of data as a table, define a database of the structure by establishing a relationship between simple tables. Regardless of the physical storage method in the database file, it can be seen as a row and column, similar to the rows and columns of the spreadsheet. In the relational database, the line is called records, and the column is called a field. Below is an example of a client table. Table 1 Client table
Customer ID Name Address City Street Postal Code 1723Doe John1234 Ffth Avenuenew Yorkny10043391SMith Mary9876 Myrtle Laveebostenma60783765Blasel Mortimer2296J River Roadpeoriail7011
Each line in this table is a record that contains all information about a particular customer, and each record contains the same type and quantity field: customer number, name, and more. Table is a logical group that is related to the relevant information of the column, similar to a workmail table. Each column in the field database table is called a field. The table is defined by various fields therebetween, each field describes the data it contains. When you create a database, you must assign a data type, maximum length, and other properties for each field. Fields can contain various characters, numbers, and even graphics. Record the information related to each customer stored in the table, called record. In general, any two records cannot be the same when the database table is created. The key key is a field (or multiple fields) in the table, which (we) is indexed for a quick retrieval. The key can be unique or unique, depending on whether it (we) is allowed to be repeated. The unique key can be specified as the primary key to uniquely identify the table. For example, in the previous example, the customer identification number (customer number) is the primary key of the table, because the customer number uniquely identifies a customer. The relational database can be composed of multiple tables, and the tables can be associated with each other in different ways. For example, a customer database can also have a table containing all orders of a customer. It only uses the "Customer" field to reference the order of the custom, not all customer information in the order table, as shown in the following table: Table 2 Order Table
Declaration customer number date The number of content is 1476433912/23/9427 $ 22.951493233913 / 17/9446 $ 9.571510887652 / 15/9627 $ 22.95
In this table, the client number field references the customer number field in the client table, which links orders and customers. It can be seen that the customer 3391 (Mary Smith) ordered 27 items on February 23, 94, ordered 46 items on March 17, 1994. The key used to establish a relationship is called an external key because it is associated with the primary key of the "external" table. One-to-many and multi-related multi-relations the relationship type is called a couple, because a customer can send multiple orders, and a particular order can only be sent by a customer. Multi-to-many relationships can also be established. For example, all of all options available (inventory): Table 3 Display Table
Content Description Supplier Cost Save 27straw Hatgarden Supply Co. $ 14.005046Garden GloveSgarden Supply Co. $ 4.5075102Hangingfloral Industries $ 6.00137 From the disk store, you can see that there are many-to-many relationships between customers and inventories. That is to say, a customer can order multiple deposit items, and one in stockbook can be ordered by multiple customers. Multi-to-many relationships are defined by two independent pairs, and the public "multi" table contains external keys for two other tables. In this example, the order S table is associated with the Customer table (via "content"). Through these three tables, we can see, Mary Smith ("Content" 27) and Garden Gloves ("Content" 46), while Mary Smith and MortiMer Blaselflatz ("Content" 46) Customer number 8765) Order Straw Hat ("Content 27). If you connect the relevant fields of the client table and the disk memory with the "order" field of the order table, build a "associated" table, then this relationship is clearer. Table 4 Association Table: Sort by customer number and content
Delivery customer number name content Description 147643391smith mary27straw hat1493233391smith mary46garden gloves151688765BLASELFATZ MORTIMER27STRAW HAT
The task of standardizing database designers is to organize data, and the method of organizing data should be able to eliminate unnecessary repetitions and provide fast findings for all necessary information. In order to achieve this goal, the process is separated into a variety of independent forms, called standardization. Standardization is a complicated process for specification with many specified rules and different levels. The process of this process has exceeded the scope of this article. However, the normalization of most simple databases can be done with the following simple empirical rules: tables containing duplicate information must be divided into several tables to eliminate duplicate. For example, the student database corresponding to students and courses contains the information shown in the table below. table 5
Student Course Description Professor 14Introduction to PhysiologyDawson23Applied BasketweaingCarruth31physics for Short - Order Cooksadms42Introduction To PhysiologyDawsons
If there is a 1000 students of the twelve courses, the instructions and teachers of each course will show more than 100 times - each student who has selected the course is repeated. To avoid this inefficiency, you should divide the table into two separate gauges to standardize, one is used to express students, and the other is used to express the course, as shown in Table 6, Table 7.
Student courses 14233144
Course Description Professor 1Physics for Short - Order Cooksadms2Counterculture SociologyBeckely3Applied BasketweaingCarruth4introduction to PhysiologyDawsons Table 6 Table 7
Now the table is standardized, so you have to change the course description or "data" of a specific course, as long as a record can be changed. The above is the basic knowledge of the database, which is necessary to learn the database programming. Although database technology acts as a discipline, its depth and breadth are not described in this point, but it should be sufficient as entry and simple database programming. Ok, let's start practice. We often encounter a database system is a registration system. Whether you are in units, or to participate in what organization, registration is inevitable, and its structure is relatively simple, we take a registration system as an example. Analyze the data involved in the system. Second, the knife is incorrectly chopped for registration, information to be tracked includes: ● Name ● Gender ● Birth ● age ● Yearbook ● Unit ● Address ● Postal Coding ● Telephone ● Fax Of course, you can simply create a table, Each of the data items described above corresponds to a field. Now you need to assign primary keys to the table, to uniquely identify each record, adding registration numbers from the registration form as the only key, so that the two records in the database are different. After making the above analysis, we can start building a database. Third, the construction of the Camp Zhazhai Here we learn how to build a database, first of all, you need to determine the type of database to establish a database. Access the following databases through the Data Access Control or Data Access Object (DAO) in Visual Basic: 1. Jet database, Microsoft Access 2. ISAM database, such as: DBASE, FOXPRO, etc. 3. ODBC databases, all client / server databases that follow the ODBC standard. For example, Microsoft SQL Server, Oracle Generally, if you want to develop a personal small database system, use the Access database to develop large, medium-sized database systems are more appropriate to use ODBC databases with an ODBC database. Due to the DBASE and FoxPro databases are not used by the time, unless otherwise, don't use it. In our example, of course, the Access database is selected. There are two ways to establish an Access database: one is to establish a database in Microsoft Access. Click the "New" button to create a new table (Figure 1). Here we mainly introduce the second method: use visual data manager, you can create a database without programming. Visual Data Manager is a very useful application that is VB Enterprise Edition and Professional, under the directory /../devstudio/vb/samples/visdata, its interface is shown below. Click on the "New" item "The version 7.0 MDB" item of "New" subkey under the menu "File" item. Enter the name "registration" of the new database in the pop-up window, the window shown below: To generate a new table, right-click the Database window pop-up menu, then select the "New Table" command, in the subsequent "table structure "To create the desired field in the dialog. Each time you add a new field to the table, click the Add Field button, the Add Field dialog of Figure 4 will appear. The options in the Add Field dialog are shown in Table 10. According to the type of field, some options are invalid, and they cannot be read. In our registration database, the types of each field are in Table 11. It should be noted that because the field registration number is used to uniquely log record, it cannot be entered by the user. So when defining this field, you need to be defined as a long data type, and the Auto Generate Fields item is valid and select this. Thus, when the user enters a new record, the system automatically enters a value different from other records on this field.
In the Access database, the keyword is implemented with an index. As the programmer programming the recording set of the table type, the index name is required. In the query, RushMore technology automatically optimizes queries with index information. After completing the table definition, click the "Add Index" button to pop up the window shown in Figure 5. There are three options on the right side of the window, which means that Table 12. Add the Index dialog box after completion, as shown in Figure 6. Of course, the establishment of the learning database is not a one-powered thing, the reader may wish to practice more. Below you can run VB to start our programming. Fourth, thousands of miles will meet the Visual Basic database application has three parts, as shown in Figure 7. User programs are programmers develop, and it is also part of us to write in VB. The database engine is a database driver. Using its programmer can access various databases in a unified format, regardless of this database is a local Visual Basic database or other database format, data access objects and programming Technology is the same. The database is part of our finished. From this structure, it can be seen that the user is independent of a particular database being accessed. Then we need to write a database program with VB, you need to enable the program to access the specified database. If it is a simple database application, you can use the DATA control to perform most of the data access operations, and do not write code at all. The controls bundled with the DATA control automatically displays data from one or more fields from the current record. The DATA Data Control Attributes The Connect property specifies the open database type and includes parameters such as users and passwords. For example: Open Access Database (Default) Connect = "Access" Opens ODBC Database Connect = "ODBC; Database = ??; uid = ??; pwd = ??; DSN = ??" DatabaseName Property determines which one of the data controls database. For multi-table databases, it is a specific database file name, for example: Access database DatabaseName = "D: /.../ demo.mdb" For a directory where a specific database file is a specific database file, the specific file name is placed In the RecordSource property, for example: access foxpro database file D: /fox/demo.dbfdatabaseename= "d: / fox" RecordSource = "DEMO" without the file extension RecordSource Property Determines the record set of the data control, namely: the data to be accessed content. It can be a table name, store the query name or SQL statement. For example: Access Register Table All Data: RecordSource = "Register" Access data born before 1973 in the RC table: Recordsource = "Select * from register where [birthday] <# 1/1/1973 #" Note: When we are running When this property is modified, you need to call the Refresh method to refresh the recordset. Method Refresh Method When we modify the RECORD-SOURCE attribute at runtime, you need to call the method to refresh the recordset. The UpdateRecord method writes the data of the controls that bind the controls on the data control to the database. That is: When we modify the data, call the method to determine the modification. The Cancelupdate method rereads the data in the database to the controls that bind them on the data control. That is: When we modify the data, call this method to give up the modification. The event validate event occurs when we move the record set record pointer.
For example, when we move the record set record pointer from A When generating a Validate event, the recording pointer is still recorded. Sub xxxx_validate (action as integer, save) where: Action points out how to generate this event, such as movement, increase, query, etc. Save indicates whether the modified data is saved. When we modified the data that binds in the data control, there is no UpdateRecord, and when the pointer is moved, save = true. If save = false is made in the event, give up the modification. For example: SUB XXXX_VALIDATE (ACTION As Integer, Save As Integer) if Save Theni = MSGBox ("DADA CHANGED, SAVE?", Vbyesno) if i = vbno thensave = false = vbno Thesave = false = vbReposition event When we move the record set pointer. For example, when we move the record set record pointer from A to record B, the recording pointer is moved to B when generating the Reposition event. Usually we display the current pointer position in this event. For example: SUB XXXX_Reposition () xxxx.caption = ?? xxxx.recordset.absolutePosition 1END SUB After you understand the Data control, we can connect the database. Now we can write an app. Because though we have established the Register database, there is no data in the database, our program's purpose is to enter data to the database. Its operation is shown in Figure 8. Each text box is just a field of table Register, entering data in the text box, and click the "Add" button to complete a record input. Let's take a look, how the DATA control is connected to the database, and how each text box is bundled with the Data control. In the Connect property of the Data control, select the Access item, in the DatabaseName property, enter "C: / Temp / Registration .mdb", in the RecordSource property, select "Register", which complete the database and Data control Connect, that is, the connection to the application is completed. What is the field in the database and how the text box is connected? In VB, we can bind the normal control on the data control to complete the data that is automatically displayed, update the record set. Commonly bindable controls include: Label, Text, Checkbox, Image, etc. Complete the binding by setting the DataSource and DataField properties of these controls. DataSource Attributes indicates which data control binding to, we may use multiple data controls in the program. The DataField property indicates which record binding to the recordset. Now we need to connect Text1 to the name field in the table "registration". After completing the connection of the DATA control, in the DataSource properties of the Text1 control, select "DATA1", in the DataField property, select the Name value. The same method is used to bind each text box to the corresponding field, and complete the bundle of the text box. Below we write two buttons commands to complete their corresponding operation. Hey! Don't worry, there is an important object that has not been told! When the application starts, the DATA control is automatically initialized.
If both CONNECT, DATABASENAME, OPTIONS, RECORDSource, Exclusive, Readonly, and RecordSetType properties are legal, the Microsoft Jet database engine will try to create a new RecordSet recordset object based on these properties. The RecordSet object can represent records in the table or as a record of query results, using the RecordSet object can be processed on the database at a record level. This is a very important in database programming and is more complex objects. The Recordset object has three types: table, dynamic set, snapshot, and there is a significant difference between them. The table type RecordSet object refers to the table that is opened when the table in the current database is created. Subsequent data operations are done directly. You can only open the table type record set for a single table, and cannot open the table type record set on the coupling or joint query. The search and sorting speed of the table type are the fastest than other types of Recordset objects. The dynamic set type RecordSet object can be a local table, or the row query result is returned. It is actually a series of references to records in one or several tables. Dynamic sets can be extracted and updated from multiple tables, including tables in other databases of links. The dynamic set type has a distinctive feature: different databases can be updated. With this characteristic, tables in different types of databases can be updatedly updated. The dynamic set and its basic table can be updated each other. If the record in the dynamic set changes, the same change will also be reflected in the basic table. When opening a dynamic set, if other users modify the basic table, the dynamic set will also reflect the modified record. The dynamic set type is the most flexible RECORDSET type and is also the strongest function. However, its search speed is not as possible with other operations of the Table type of Recordset. The data containing the snapshot type RecordSet object is fixed, which reflects the status of a momentary database that generates a snapshot. Snapshots from Microsoft Jet Data Sources are unrecognizable, some snapshots obtained from open database interconnect (ODBC) data sources can be updated, depending on the ability of the database system itself. Compared with the dynamic set type and Table type Recordset object, the snapshot has less processing overhead. Therefore, it performs query and return data faster, especially when using ODBC data sources. The snapshot type saves the full replica of all records in the table, so there are many numbers, and the performance of snapshots will be much slower than the dynamic set. In order to determine the snapshot and dynamic set, you can open the record set in a dynamic set, and then open it in a snapshot mode. What record set is specifically used, depending on the task you need to complete: Is it necessary to change the data, or simply view the data. For example, a table can be used if you must sort or use an index. Because the Table type of Recordset object is indexed, it is the fastest speed. If you want to update a series of records selected by query, you can use a dynamic set. If you cannot use a recordset of the table type without scanning the record, you may be free if you use the snapshot type. In general, use the table type Recordset object as much as possible, it is usually always the best.
To select a specific RECORDSET type, set the RecordSetType property of the DATA control to: RECORDSET Recording Set Properties BOF Attribute When the Recording Set Record Pointer Note Trueeof Attributes When the Record Record is recorded When the record set record pointer points to the last record, return TRUEABSLOUTEPSITION properties return The current record set record pointer, the first record is 0, is the read-only property Bookmark property String type, returns or sets the bookmark for the current recordset record pointer, is the readable write properties. Each record has its own unique bookmark, which is independent of the order of records recorded in records. Store the Bookmark property into the variable, followed by assigning the variable to the Bookmark property and returns to this record. Note: Use the Bookmark property to relocate the record pointer in the program without using the AbsloutePositionNomatch property. Often use with the bookmark properties. For example: Find the first name in the [Name] field DIM S is StringWith XXXX.Recordset S = .BOOKMARK .FINDFIRST "[Name] Like 'Lee *'" if .nomatch the msgbox "Data Did not find" .bookmark = S End IFEND with Recording Set Method ADDNEW Method Add a new recordset to the recordset delete method from the recordset to delete the current record. Use the MOVENEXT method to move the pointer after delete. For example: with xxxx.recordset .delete .MOVENEXT IF .EOF THEN .MOVELASTEND WITHMOVEXXXX method Movefirst Move record set pointer to the first record on MoveLast Move record set pointer to the last record on MovePrevious to move record set pointer to the previous one Record MOVENEXT Moves Recording Set Pointer to the next Record Findxxx Method FindFirst In Recording Concentration Query Equity First Record Findlast In Record Concentration Query Equity Conditions FindPrevious In Record Concentration Query Query Former Record Findnext In the recordset, the next record is good, with such a full knowledge, write two buttons commands simply a small dish, first try, add a "Add" command button. PRIVATE SUB Command1_Click () data1.recordset.addnewend Sub Wow! How is it so simple, then look at the "Delete" command button private submmand2_click () data1.recordset.delete data1.recordset.addnewend Sub like this? Run the program, OK! Everything is normal, can't wait to enter a record, click the "Add" button, how? there is a problem! Because you can only enter the data after the addNew method, well, add a new record when the window is initialized. Private subform_initialize () data1.recordset.addnewend Sub Enter the data, we intend to exit the program, very natural, we do the closed window operation, and end the input work smoothly. Really smooth? Open the database to see the data in the database, we found that the last record just entered is not stored in the database.
This is very good explanation, whenever we call the AddNew method, it stores the input record into the database, and when we turn off the window, the recorded record is not saved to the database, then the DATA control is before turning off the window. A refresh can be stored in the database. Private Sub Form_Queryunload (Cancel As INTE GER) DATA1.REFRESHEND SUB is here, we seem to be slightly easier, and this window is almost complete. But I have to give you an advice: In the database system, you should try to handle the error in the application level. This sentence seems to be a bit abstraction. It is actually simply in this program. In Table Register, we define the date of birth as a DATE / TIME type. If you are running at the program, what happens when you enter the DATE / TIME format in this field, what happens when you submit data to the database? The database will report an error message to the user. However, this is not good for the application, and such an error should be handled by the user program instead of being handed over to the database to process, it should check if the input of the field is legal before the data is submitted. Private sub text3_lostfocus () if isdate (Text3.text) or text3.text = "" "Check if you enter legitimate data exit suvend ifmsgbox (" Enter an error, please enter your birthday! "), Will choose not legal Data to re-enter and make the control focus. TEXT3.SETFOCUSTEXT3.SELSTART = 0Text3.sellength = LEN (Text3.Text) End Sub top is a small example of the application handling error, but this is based on the application level The mistake is very important. 5. Finding in the database management system, input and query is inseparable from two twins sisters, and below will introduce how to create a query window. The design of the query window is divided into two parts: query results and query conditions. The result of the query refers to the data required by the user, which includes the records queried according to the query condition, but not the data in each field in the table needs to be provided. For example, in our example, the value of the registration number in the registration table is not interested in the user, so in the query result, we do not want to display the value of the regid field. The query condition is the query requirements proposed by the user. For example, in our system, you can have a name condition. When the user wants to know a person's specific situation, he can enter this person's name, and check out the situation in this person; or age conditions, when the user enters The age group will query information from all of this age group. Which query conditions are used in the end, this requires developers to design according to the requirements of users and systems, and their specific implementation process is mostly different. In order to save space, we only query with age. The search window is running as shown in Figure 9. In this program we use a control DBGRID, this control is used to display the query result, select "Parts ..." items under the VB "Project" menu, in the control tab, select "Microsoft Data Bound Grid Control 5.0" However, the small icon of the DBGRID control will appear in the toolbox. It is the same as other controls. In order to connect to the database, the DATA control is indispensable, recalls, how to set its properties, OK! Like the input window, in the Connect property, select the Access item.
In the DatabaseName property, enter "C: / Temp / Registration .mdb". In the RecordSource property, select ... Hey, hey, here is a bit a bit slightly, if the settings are as set as the input window, the registration number field is included in the query results. In this property, we should enter SQL statements: SELECT NAME AS Name, SEX AS Gender, Hometown AS Age, AGE AS Age, Birthday AS Birthday, Company AS Unit, Address AS Address, Zip AS Zip, Telephone AS Phone, Fax AS Fax From register. Don't worry, although this statement is a bit long, it is actually relatively simple. The syntax of this statement is: SELECT field name, field name, ... from table name where conditions; comparison grammar, we can see the meaning of the input SQL statement: Query your name, gender, bostric, ... from the table register The value of the field. As long as the registration number field is not selected in the field list, the value of the registration number will not be displayed in the query result. If you are careful, you will notice that in the list of SQL statements we have written in the field name, it also adds AS ... items after it, such as "Name As Name", this is the Name field Take an alias "name" to display the "name" instead of "name" when the field name is displayed in the DBGRID control. Setting the DATA control attribute to bundle the DBGRID control to the DATA control, which is the same as the input window. Yes, set the "DataSource" property to "DATA1". Now you may wish to run the program, really exciting, DBGRID displays all the information in the table. How can I display the requirements of the requirements? Look at the SQL syntax above, you can enter query conditions after the WHERE segment, such as personal information between ages 20 to 30, whose statement is: SELECT NAME, ... from Register WHERE AGE> 20 And Age <30; We can complete the conditions to complete the condition query by forming a new SQL statement based on the condition input by the user. The entire program is very simple. When the user enters the age group in the text box, tap the Query command will display the qualified query results.
The program code is as follows: option expectitconst allinfo = "SELECT NAME AS Name, SEX AS Gender, Hometown AS Gender, AGE AS Age, Birthday AS Birthday, Company AS Unit, Address AS Address, ZIP AS Zip Code, Telephone AS Phone, Fax AS Fax from FROM Register "'Defining SQL Query Statement Private Sub Command1_Click () DIM T1, M, N AS STRING' Constructs the WHERE Conditions of SQL Statement If ISNUMERIC (TEXT1.TEXT) THEN M =" AGE> " Text1.Textend IFIF IsNumeric (Text2.Text) THEN N = "Age <" TEXT2.TEXTEND IFIF M = "" And n = "" THEN T1 = "" Else IF M = "" THEN T1 = N else if n = "" T1 = m "AND" N end if end ifnd IFIF T1 <> "" T1 = "Where" T1END ifdata1.recordsource = Allinfo T1 'Set the value of the RecordSource property to a new SQL statement Data1.Refresh 'refreshes the database, gets the query result that meets the current condition End Sub In this program, you can also add a name query, a born query, etc., its design process is implemented by constructing the SQL statement. In addition, it is necessary to note that since it is a query window, of course, it is allowed to modify, set the allowupdate attribute value of the DBGRID control to False. OK! Run the program, ah! Everything is good. Take a look at the app, then look at the code you wrote, incredibly, such a short code actually completed such a powerful function. This is the case, the most important thing in database programming is the clearness of the concept, compared with the trick, and it seems to be in the secondary position. Let us close your eyes, think about what we need to know what things: DATA control, RecordSet object, bundle of control, simple SQL query statement. Familiar with these things, you can program a database, if you are more interested in developing database systems, you can strengthen your knowledge in database design and SQL statements. But is the database programming is really simple? If you are already familiar with the above, I suggest you look at the following section. Sixth, I will remember that we have said that Visual Basic has provided two ways to interface with the Jet database engine interface. DATA controls and data access objects. We have already seen the DATA control, which is indeed unimeding, but the DATA control only gives a limited access to the existing database. The DAO model can fully control the full programming interface of the database. These two methods are in fact not mutually exclusive, in fact, they often use. The DAO model is an object class collection for the design of the design relationship database system. They provide all operating properties and methods required to manage such a system, including creating databases, definition tables, fields, and indexes, establishing tools such as relationships, positioning, and querying databases. The main object of the DAO structure is shown in Figure 10.
Database programming in Visual Basic is to create a DAO (Data Access Object). These objects correspond to different parts of the accessed physical database, such as Database, TableDef, Field, and Index objects, with the properties and methods of these objects to implement the operation of the database, can use bindings and non-bound in the Visual Basic form The control is displayed to display the results of the operation and receive user input. This simplifies the code, which gives a large flexibility to programmers. Since the same objects, properties, and methods can be used to handle a variety of different database formats. At the same time, if it becomes from a database format to another (for example, convert a local Microsoft Access database into a network SQL Server database), you can adapt to this change with a small amount of code. You can even create such an application, connect the table from multiple different databases in a single query or report. Let's introduce the DAO object, from the above picture we can see that the most critical is the DBENGINE object, all database operations are completed. The DBENGINE object DBENGINE object is equivalent to the Jet database engine, and does not need to create the object. CreateWorkspace: Create a workspace object example: Dim ws As WorkspaceSet ws = DbEngine.CreateWorkspace (SpName, UserID, password ", SpType) wherein SPName workspace name StringUserID username password StringSpType workspace StringPassword Type = dbUsejet jet workspace = dbUseODBCODBC Workspace Workspace object Workspace object defines a session to create a security level through the username and password associated with it. You can use the default workspace DBENGINE.WORKSPACE. Method: OpenDateBase Opens a database close Current Workspace Begintrans Launched a Transaction COMMITTRANS Submit the current transaction Rollback rollback Current transaction, for example, if we need to open a database. We call Workspace's OpenDatabase method to open a database. For example: Dim DB AS DatabaseSet DB = OpenDatabase (DBNAME, EXC, Readonly, Source ): DBNAME database file name (for a single table database is path) EXC = true indicates that the database cannot be accessed by other applications. False represents sharing open database readonly = true indicates that after opening the database, only the database After reading operation = false, after opening the database, you can read and write the database to the database, which is used to specify the open database type. Creating a record set We use the Database object's OpenRecordset method to open a record set. For example: DIM RS AS RecordsetSet RS = DB.OpenRecordSet (Source, Type) where: Source Specifies the content of the record set, it can be a table name, query name or SQL statement Type creation record set type = DBOPENTABLE Type Record Set = DBOPENDYNASET Dynamic Recording Set = DBOPENSNAPSHOT snapshot record set Access ODBC Database Visual Basic can identify three types of databases through the DAO and JET engine: Visual Basic database, external database, ODBC database.