VisualBasic3.xForWindows is a very good language for developing Windows applications. It can be used to develop large-scale application systems. It has the ability to access various databases. Below we will talk about several issues that should be paid attention to when using VB to access the database.
1. How to access the database. VB provides two methods for accessing the database, one is to use data control, and the other is to use objects to access the database. In both methods, the properties of the database are involved: connect, databasename, exclusive, options, readonly, recordsoure. These attributes are introduced in many books, so I will not go into details. But sometimes when you set up connect and databasename and then set recordsoure as described in the book, the error "Unable to find installable ISAM" often appears. The [ISAM] mentioned here is in the VB.INI file, which specifies the dynamic link library of the accessed database for VB. The name of the database used in connect must match the name of the database in [ISAM], so that the database can be opened easily.
2. About the bookmark pointer, that is, the bookmark attribute. When VB accesses the database, the records in the database do not have record numbers. However, VB provides the bookmark attribute to record the record pointer of the currently accessed record. This bookmark is equivalent to the record number. However, when programming, I found that the bookmark attribute when using database control and opening the database with an object to access the same database is not universal between the two. When you use a bookmark to record the current record pointer of a database opened with data control, and then use an object to open the database, and use the bookmark of data control to find the location record, an illegal bookmark error will occur.
3. Pay attention to the difference between hide method and unload method. The Hide method hides the form you specify, but does not delete it from memory, so the content of the form does not change. The unload method deletes the specified form (disappears from the screen and deletes it from the memory). For example, if you use the grid control to display the record content in the current form, and then use the hide method to hide the form, then you reselect the records and load them into the grid control, and use the show method to display the hidden form. At this time, the content in the grid is still the old content and the new content does not replace the old content. Here you need to use the unload method to delete the form, and then load the new records into the grid control. When displayed using the show method, you can see the new content.
4. Pay attention to the matching of variable types. When accessing the database, grid control is generally used to display records. Where grid.text is a substring type. But some recorded data items are empty (null), that is, there is no data. Obviously, an error will occur if null is loaded into grid.text. So here you need to add type judgment and assign null data items to empty space strings, so that this problem can be solved.
5. How to print database records in grid format. The printer output objects provided by VB include forms, text boxes, picture boxes and reports. Report control can be used here to achieve grid format printout. But report control requires the report format file .PRt. This file is designed by the report editor provided by VB to design the report format you need. The generated report file outputs all the records in the database, but often we only need some of the records in the database that meet the conditions. How to achieve grid format printing of partial records? The method used by the author is to use the report editor to design a connection to an empty database file, and then load some of the records that meet the conditions into the empty database during the running of the program, and then use the report control to print the output, so that you can achieve whatever you want. Report printout that requires data.
6. Pay attention to calling system DLLs (dynamic-link libraries). VB is a high-level programming language that does not have some functions of low-level languages. It is difficult to access machine hardware and other operations. If you call Windows application programming interface (API) functions through a DLL, you can easily access the hardware. The system's DLLs include keynel library, gdi library and user library. The keynel library is responsible for memory management and file management, the gdi library is responsible for display and printing functions, and user is responsible for the management of keyboard, mouse, sound, communication, and system timing. At the same time, VB can also call DLL written in any language. Therefore, if you want to compile a high-quality application, you must learn how to call DLL to achieve the required functions.
In short, the Visual Basic language has various powerful functions. The above are just some of the author's little experiences in programming. I hope it can be helpful to the readers. ->