Code
// Adotest. cpp: Define console applicationsProgram.
//
# Include " Stdafx. h "
# Import " C: \ windows \ system32 \ msado15.dll " No_namespace Rename ( " EOF " , " Adoeof " )
Int _ Tmain ( Int Argc, _ tchar * Argv [])
{
: Coinitialize (null );
_ Connectionptr m_pconnection;
Hresult HR = M_pconnection.createinstance (_ uuidof (connection ));
If ( ! Succeeded (HR ))
{
STD: cout < " M_pconnection.createinstance (_ uuidof (connection) Error " < STD: Endl;
Sleep ( - 1 );
Return 0 ;
}
STD :: String Str = " Provider = sqloledb.1; Password = sa; persist Security info = true; user id = sa; initial catalog = success; Data Source = WUBIYU-PC " ;
M_pconnection -> Connectionstring = " Provider = sqloledb.1; Password = sa; persist Security info = true; user id = sa; initial catalog = success; Data Source = WUBIYU-PC " ;
Try
{
M_pconnection -> Open (_ bstr_t) Str. c_str (), "" , "" , Null );
}
Catch (_ Com_error & E)
{
STD: cout < " Opening failed: " < E. Description () < STD: Endl;
Sleep ( - 1 );
Return 0 ;
}
_ Recordsetptr recordsetp;
If (Failed (recordsetp. createinstance (_ uuidof (recordset ))))
{
STD: cout < " Failed to create recordset object: " < STD: Endl;
Sleep ( - 1 );
Return 0 ;
}
Try
{
// Recordsetp-> open (_ variant_t ("sell_agent "),
// _ Variant_t (idispatch *) m_pconnection, true), cursortypeenum: adopenkeyset, locktypeenum: adlockoptimistic, commandtypeenum: adcmdtable );
// Recordsetp-> open (_ variant_t ("sell_agent "),
// _ Variant_t (idispatch *) m_pconnection, true),: adopenkeyset,: adlockoptimistic,: adcmdtable );
}
Catch (_ Com_error & E)
{
STD: cout < " Opening failed " < E. Description () < STD: Endl;
}
// STD: String sorted STR = "Update sell_agent set integral = 21 where id = 2 ";
STD :: String Reverse Str = " Select * From sell_agent where id = 2 " ;
_ Commandptr pcmdchange;
HR = Pcmdchange. createinstance (_ uuidof (command ));
If ( ! Succeeded (HR ))
{
STD: cout < " CREATE command object Error " < STD: Endl;
Sleep ( - 1 );
Return 0 ;
}
Pcmdchange -> Activeconnection = M_pconnection;
Pcmdchange -> Commandtext = (_ Bstr_t) Comment Str. c_str ();
M_pconnection -> Errors -> Clear ();
_ Variant_t recordscount = 0 ;
Recordsetp = Pcmdchange -> Execute ( & Recordscount, null, ad1_text );
STD: cout < ( Long ) Recordscount < STD: Endl;
Try
{
STD: cout < Recordsetp -> Getfields () -> Count < STD: Endl;
Recordsetp -> Movefirst ();
While ( ! Recordsetp -> Adoeof)
{
Int Id_value = ( Int ) Recordsetp -> Fields -> Item [_ variant_t ( " ID " )] -> Value;
STD :: String ID = (_ Bstr_t) recordsetp -> Getfields () -> Getitem (( Long ) 0 ) -> Name;
STD :: String Name_value = (_ Bstr_t) recordsetp -> Getfields () -> Getitem (( Long ) 1 ) -> Value;
STD :: String Name = (_ Bstr_t) recordsetp -> Getfields () -> Getitem (( Long ) 1 ) -> Name;
STD: cout < Id. c_str () < " : " < Id_value < " " < Name. c_str () < " : " < Name_value.c_str () < Endl;
Recordsetp -> Movenext ();
}
}
Catch (_ Com_error & El)
{
STD: cout < El. Description () < STD: Endl;
}
STD: cout < " Complete " < STD: Endl;
: Couninitialize ();
Sleep ( - 1 );
Return 0 ;
}