From the last in the VC Knowledge Base published "Use ADO Encapsulation Class database program development example" after a article, get many netizens response, very feel gratified. But because I am not fully proficient in ADO, so the last write class is very imperfect, and may even bring some friends trouble, so always want to write it a little more perfect.
Now write this class function should be said to be more perfect, basically encapsulates most of the ADO component methods, and extended some people commonly used methods, such as the file or picture written to the database, from the database read out bitmap fields, the value of the field of intelligent conversion and so on.
Because it was not enough time, I almost did not have any effective test of the command class, and did not write the relevant documents, and the connection and recordset class documents are not very clear, perhaps someone will say I am very irresponsible. Oh!
In this test program, I tested most of the methods for connecting classes and recordset classes, including access to commonly used data types, add delete, and so on, there are multiple data types with integer, double, character type variable read, which is the best character compatibility, basically for most data can return valid values, The second is the double, and integral type, which cannot read the values of fields such as character type, date type, and so on. In addition to the two images of the properties of some tests, of course, there are many attributes can not be fully tested.
I've learned a few things that are useful in developing ADO-related programs, such as Setfilter,setsort,find, bookmarks, and so on, which allow you to manipulate records effectively without having to figure out how to build SQL statements to do so.
There is also a way to import the exported XML file, I do not know if this method is useful, because it is not very good for Chinese support, exported XML file can not display the normal Chinese.
The last one is the DataGrid control and Recordset binding, I think this should be a more useful technique, I have never thought before, in VC can also learn VB binding database, so do not have to write what code can easily modify the data.
Code in (VC6 + SP5)/vc7 + Windows XP English Professional Edition/Windows 2000 Chinese Professional Edition/Windows 2003 English beta/windows 2003 Chinese Enterprise Edition is compiled and passed, and in Access, Sqlser ver, MySQL under the test, in addition to MySQL does not support transactions, and other methods, most of the methods can pass the test.
In principle, I acquiesce to your freedom to use, modify, or propagate this code, but if you are used in a certain project or for commercial purposes, then please note that I will not be responsible for the damage caused by the code bug, or the copyright issue to you.
Because the first package so many and is not very familiar with the things, there is any improper place also please more advice.
The code for this article runs the following chart:
Here are a few of these encapsulation classes:
Cadoconnection class
Class Members:
Constructors: Cadoconnection ()
Creates a connection object.
Open Method:
BOOL Cadoconnection::open (LPCTSTR lpszconnect, long loptions)
Connect to a data source.
Params:
[Lpszconnect]: The connection string that contains the connection information.
[loptions]: Optional. Determines whether the method connects the data source in a synchronous or asynchronous manner. Can be one of the following constants:
constant |
Description |
Adconnectunspecified |
(default) to open the connection synchronously. |
Adasyncconnect |
Open the connection asynchronously. ADO uses the ConnectComplete event to notify that the connection has completed. |
BOOL Cadoconnection::connectsqlserver (CString dbsrc, CString dbname, CString user, CString Pass, long loptions)
Connect to the SQL Server database.
BOOL cadoconnection::connectaccess (CString dbpath, CString Pass, long loptions)
Connect to an Access database.
Params:
[DBPath]: Access MDB database file path name.
[Pass]: access password.
[DBSRC]: SQL Server server name.
[dbname]: The default database name.
[User]: username.
Openudlfile Method:
BOOL Cadoconnection::openudlfile (LPCTSTR strFileName, long loptions)