Non-Access database programming and applications in VB

zhaozj2021-02-11  229

Non-Access Database Programming and Application Summary Visual Basic has a strong powerful data library, not only enough to directly support the MS Access data library, and through the ISAM driver of the inner installation, it can bind to FoxPro, DBase, etc. Being external database. This paper not only discusses VB's support from the VB database architecture, but also combines some instances to specifically expound the use of data inventory object variables to achieve new, library structural modifications, display and operation of these foreign databases. Environmental settings. Key words Visual Basic Access Database Database Database Solution to Icon Variable Software For a Functional Windows Software Development Station, Visual Basic Property Edition provides a strong support for data libraries. Especially for the use of data controls and binding controls, the data library is used to use the Data Access Object Variable, and the DCC is directly adjusted by the ODBC 2.0 API interface function. The MS Access Database of its standard, which can provide not weakened in the support of the professional database software, and can carry out the full data library maintenance, operation and its affairs. In VB, the non-Access data library is called an external data library. For FoxPro, DBASE, Paradox, etc. Although the Data Manager, which can help VB can enter New, Open, Design, Delete, etc., but cannot be realized from the bottom layer in the operational state of the application. This paper starts from the method of using data inventory to take object variables, and implements the new library of non-Access format database (as an example), copy database structure, dynamic transfer, etc., explains these externalities from programming skills. Database supports insufficient feasibility. First, the VB data library's system of structural vb's data warehouse, please look at the picture below. It can be seen that the core structure of the VB database is the so-called Microsoft Jet database engine. The role of the JET engine is like a "panel", which can insert a variety of ISAM (Indexed Sequential Access Method, the index order access method) data driver. . The JET Engine provides a direct-in support for the Access format database, which is the true cause of VB on Access Database.

The ISAM driver of databases such as FoxPro, DBASE (or XBase), PARADOX, BTRIEVE, which enables VB to support these data library formats. In addition, his many compatible ISAM drove program can also be obtained through the after-sales service from the factory. Because of the discussion As can be seen, the MS JET engine is essentially provided: a syntax analyzer that conforms to the ANSI standard; the memory management function provided for the use of the query result set; the external interface of the supported database; internal interface provided for application code . In practice, transformation from a database type in VB is another data library type, no need to modify or only have few code modifications. Moreover, although DBASE, Paradox itself's DDL (Data definition language, data definition language) and DML (Data Manipulation Language, the data manipulation language) are non-structured queries, but they can still use VB's SQL statements and Jet engines. manipulate. From the perspective of the program code of the VB, the ODBC, ISAM driver program and the entire outer knot of the MS Access data library can be uniform to a consistent interface. That is, it is to say that the record set of the VB application program is intertwined with the data library format and type of the like. That is, the database such as FoxPro is still allowed to use the many data libraries to reject the object variable, which provides the most important method for non-Access Database. Second, the parameter setting and configuration file when using a non-Access database, if the database is used in the VB program, a configuration must be provided (.ini) ) File, you can set different types of databases in the INI file. If this INI file is not found, it will lead to the database. In the case of normal conditions, the file name of the INI file is the same, and the name of the application program is not indicated. The program of VB will be found in the Windows subdirector. Ini file. You can set the INI file with the SetDataAccessOptions statement in VB.

The usage of the SetDataAccessOptions statement is as follows: SetDataAccessOptions 1, inIfilename Its IniFileName parameters refers to the path-name of the INI file. It is worth noting that when the application does not find this INI file, or when the OpenDatabase function is called, it is not set to the standard value specified by VB, if the FoxPro 2.5 format is set to "FoxPro" (" It should be "FoxPro 2.5;"), or no corresponding ISAM driver is installed, then VB displays an error message "Not Found Installable ISAM". Tongmong, INI documents are generated before the application process is generated, or in the installation of time, it can also be produced in the application. Usually in this INI file "[options]", "[ISAM]," [Installed Isams] "," [FoxPro ISAM] "," [DBASE ISAM] "," [Paradox ISAM] ", etc. For a complete application, there should be a set of settings that belong to the application, such as "[MyDB]". DataType, Server, Database, OpenonStartup, DisplaySQL, QueryTimeout, etc. can be set in it, and should be settled in a line of operation. The Windows API interface function provides an OSWRITEPRIVATEPROFILESTRING function in the kernel.exe dynamic link library, which is written in writing information in WINDOWS (.ini) writing. In the case of normal conditions, the application program is also required to read the parameters of the associated file within the function. For example, parameters such as PageTimeout, MaxBuffersize, LockRetry, Lockretry, and the presence of the application running environment by reading these parameters, potential errors capture Wait a lot of improvement.

If the configuration file for this application is MyDb.ini, the specific process is as follows: FUNTION GetInistring $ (Byval FName $, BYVAL SZITEM $, BYVAL SZDEFAULT $) 'This custom subsystem implements the reading parameter within the INI file DIM TMP As String, x as integerTMP = String (2048, 32) x = osgetPrivateProfileString (FName $, Szitem $, SZDEFAULT $, TMP, LEN (TMP), "MyDb.ini") GetInString = MID $ (TMP, 1 , x) End function the following statement can write these functions in the module file, and each function must declare in a row declare function OSGetPrivateProfileString% Lib "Kernel" Alias ​​"GetPrivateProfileString" (ByVal AppName $, ByVal KeyName $, ByVal keydefault $, ByVal returnString $, ByVal NumBytes As Integer, ByVal FileName $) Declare Function OSWritePrivateProfileString% Lib "Kernel" Alias ​​"WritePrivateProfileString" (ByVal AppName $, ByVal KeyName $, ByVal keydefault $, ByVal FileName $) Declare Function OSGetWindowsDirectory% Lib " "Alias" getWindowsDirectory "(BYVAL A $, BYVAL B%) SUB FORM1_LOAD () DIM ST AS STRING DIM X AS INTEGER DIM TMP AS STRING TMP = String $ (255, 32) ' In the INI file, the installed ISAM driver X = OSWRITEPRIVATEPROFILESTRING ("PDX110.DLL", "MyDb.ini", "PDX110.dll", "PDX110.DLL", "PDX110.DLL", "MyDb.ini" Installable ISAMS "," dBASE III "," XBS110.DLL "," MyDB.INI ") x = OSWritePrivateProfileString (" Installable ISAMS "," dBASE IV "," XBS110.DLL "," MyDB.INI ") x = OSWritePrivateProfileString ("Installs ISAMS", "FoxPro 2.0", "Xbs110.dll", "Mydb.ini") x =

OSWritePrivateProfileString ( "Installable ISAMS", "FoxPro 2.5", "XBS110.DLL", "MyDB.INI") x = OSWritePrivateProfileString ( "Installable ISAMS", "Btrieve", "BTRV110.DLL", "MyDB.INI") x = OSWRITEPRIVATEPROFILESTRING ("DBASE ISAM", "DELETED", "On", "mydb.ini") 'Indicated the location of the INI file x = OsgetWindowsDirectory (TMP, 255) ST = MID $ (TMP, 1, x) SetDataAccessOption 1, ST "/mydb.ini" 'gets some parameters for INI files GWMaxGridrows = Val (GetInString ("MyDb.ini", "MaxRows", "250")) GlQueryTimeout = Val (GetInString ("MyDb.ini", "QueryTimeout" , "5")) GLLogintimeout = Val (GetInString ("MyDb.ini", "Logintimeout", "20")) End Sub III, Data Acquisition Object Variable Method for Programming of Foreign Databases and Its Real Example in VB Professional Database Among the three methods of programming, the second - use of data inventory to take object variables (DAO), the most powerful, flexible feature. It can access the management functions of ODBC 2.0 in the program; you can control multiple recorded category: Dynaset, Snapshot, and Table record collection objects; you can store procedures and query action; you can access database set objects, such as Tabledefs, Fields, Indexes And querydefs; with real things handling ability. Because, this method is non-commonly suitable for the majority of the data of the database. The record set pair of records in VB is independently independent, and the method of resembling the object variable in the non-Access data library can also be used in the non-Access Database. Because of FoxPro, etc., the method of using the data library to accommodate the object variable is also the best choice.

One thing to note is that only data controls (Data Control) can be accessed using data controls in the standard version of the VB, and the main data inventory objects are only Database, the Dynaset object can be provided through the properties of the data control. Other important objects such as Tabledef, Field, INDEX, QueryDef, Snapshot, Table, etc. cannot be generated in the VB's standard version, so the method of using data access object variables can only use the professional version of VB 3.0 or more. (1) Non-Access database New and library structure modified VB Professional Data inventory object variables can be divided into two categories, a class of maintenance and management for database structures, and the additional access to data . It shows that the database can be used to use the opposite side of the following: Database, Tabledef, Field, Index, and three collations: Tabledefs, Fields, and Indexes. Each combination is composed of a stem of a pair, and these data objects can be used as an array in full, and is called by an array. Once the data library is established, it can use it to modify the data library to modify and data processing. For non-Access data libraries, large scores are right to be in a directory, which can be generated in a directory of the MKDIR statement that uses VB, which is newly established. Each non-Access data library file can be seen as a data table (Table) under this directory, but it is actually independent. The lower surface is a program example of new FoxPro 2.5 format database.

转载请注明原文地址:https://www.9cbs.com/read-4001.html

New Post(0)