⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 readme.txt

📁 ado连接源代码~包括ado和adox的所有基本使用
💻 TXT
字号:
With ADO 2.0, you can bind recordset data members to a C++ structure.  
ADO will synchronize the C++ structure with data from the current record when you move from record to record in the recordset.  Visual C++ 6.0 has a ADO Data Bound Dialog Component which will create a read-only ADO data bound dialog for a particular select statement or table name.  

You can also add new records and modify existing records with the
ADO 2.0 C++ bindings.  This sample demonstrates how to convert a dialog
created by the ADO Data Bound Dialog Component into a dialog that allows
adding, updating, and deleting records using the ADO C++ bindings.

Follow these instructions to add a read-only ADO Data Bound Dialog to a Visual C++ project:

1. Select Project | Add To Project | Components and Controls...
2. Open "Visual C++ Components" folder and select "ADO Data Bound Dialog".
3. Click Insert and select OK.
4. Type in an ODBC or OLE DB connection string, or use the Build... 
   button to create a connection string using the Microsoft Data Links
   dialog box.
5. Click Next and type in a SQL statement in the Command box or
   click the Table option button to choose from a list of tables
   in the database.  Choose Next...
6. Choose the Cursor Location and the Cursor Type desired.  Note that
   it is easy to change these options later in the source code.
7. Choose Next and then Finish to complete the process.

You should now have a RsCgDlg.cpp and RsCgDlg.h file which contains
all of the code to create an ADO bound dialog box.  The wizard also
adds a new dialog resource to your project which contains the text boxes
and navigation buttons.

In order to allow updating of data, you need to make several modfications
to the wizard generated class files.

1. Modify the ADO binding macros to allow updating of each field.
   All you need to do here is change the last parameter (the Modify 
   parameter) of the field entry macro from FALSE to TRUE:

   // BEFORE
   ADO_FIXED_LENGTH_ENTRY(1, adInteger, m_lProductID, 
      lProductIDStatus, FALSE)

   // AFTER (Changed Modify macro parameter to TRUE)
   ADO_FIXED_LENGTH_ENTRY(1, adInteger, m_lProductID, 
      lProductIDStatus, TRUE)

   
2. Modify the OnInitDialog() method of the dialog class to open an 
   updatable ADO recordset versus the read-only one created by the wizard.

   // BEFORE
   m_pRs->Open((LPCTSTR)m_strCmdText, (LPCTSTR)m_strConnection,
      adOpenStatic, adLockReadOnly, adCmdUnknown);

   // AFTER (Changed adOpenStatic to adOpenKeyset and adLockReadOnly 
   // to adLockOptimistic)
   m_pRs->Open((LPCTSTR)m_strCmdText, (LPCTSTR)m_strConnection,
      adOpenKeyset, adLockOptimistic, adCmdUnknown);

3. Create a class member variable for an IADORecordBinding pointer and use
   the class member pointer to set up the ADO binding.  Note that the
   wizard intializes a local IADORecordBinding pointer named 
   pAdoRecordBinding in OnInitDialog().  This sample uses the wizard
   generated code to initialize a class scope IADORecordBinding pointer
   named m_piAdoRecordBinding.
   
   You need to cache the IADORecordBinding pointer because you need this
   pointer to trigger Updates and AddNews to the recordset.  Calling AddNew
   or Update on the ADO recordset pointer m_pRs will not update the 
   recordset --  you must use the AddNew and Update in the   
   IADORecordBinding interface to make changes to the recordset.

4. Create a method to move all of the record data from the dialog members
   to the ADO binding members.  In my sample I call this method 
   PrepareBoundData().  Note the wizard binds the text boxes in the dialog 
   to one set of member variables and binds the ADO recordset to another 
   set of member variables.   This gives you an extra buffer for comparing 
   values in the dialog with the actual values in the ADO recordset.   
   I added an additional member function to the class called IsDirty which 
   demonstrates how to check the dialog buffer against the ADO binding 
   buffer.

5. Create SaveRecord and AddRecord methods which call PrepareBoundData() to
   move the data from the dialog members into the ADO binding members and
   then call the appropriate IADORecordBinding interface method to add or
   update the record.

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -