Tangle of reading data by ADO getcollect

Source: Internet
Author: User

_ Variant_t vusername, vbirthday, vid, vold;
_ Recordsetptr m_precordset;
M_precordset.createinstance ("ADODB. recordset ");
M_precordset-> open ("select * from users", _ variant_t (idispatch *) m_pconnection, true), adopenstatic, adlockoptimistic, adshorttext );
While (! M_precordset-> adoeof) // Why is it adoeof instead of EOF? Do you still remember Rename ("EOF", "adoeof?
{
// My previousProgramThe force type conversion results always report exceptions, so they are resentful.

Vid = m_precordset-> getcollect (_ Variant_t (long) 0 )) ; /// Get the value of the 1st column and start counting from 0. You can also give the column name directly, as shown in the following line
Vusername = m_precordset-> getcollect ("username"); // obtain the value of the username field
Vold = m_precordset-> getcollect ("old ");
Vbirthday = m_precordset-> getcollect ("Birthday ");
/// Records in the output window output record set in debug mode
If (VID. VT! = Vt_null & vusername. VT! = Vt_null & vold. VT! = Vt_null & vbirthday. VT! = Vt_null)
Trace ("ID: % d, name: % s, age: % d, birthday: % S/R/N", vid. lval, (lpctstr) (_ bstr_t) vusername, vold. lval, (lpctstr) (_ bstr_t) vbirthday );
M_precordset-> movenext (); // move to the next record
}
M_precordset-> movefirst (); // move to the first record
M_precordset-> Delete (adaffectcurrent); // Delete the current record
/// Add three new records and assign values
For (INT I = 0; I <3; I ++)
{
M_precordset-> addnew (); // Add a new record
M_precordset-> putcollect ("ID", _ variant_t (long) (I + 10 )));
M_precordset-> putcollect ("username", _ variant_t ("Silverlight "));
M_precordset-> putcollect ("old", _ variant_t (long) 71 ));
M_precordset-> putcollect ("Birthday", _ variant_t ("1930-3-15 "));
}
M_precordset-> move (1, _ variant_t (long) adbookmarkfirst); // move a record from the first record to the second record.
M_precordset-> putcollect (_ variant_t ("old"), _ variant_t (long) 45); // modify the age
M_precordset-> Update (); // save it to the database.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.