Print? # Include <string>
// C: \ Program Files \ Common Files \ System \ ADO \ msado15.dll
# Import "msado15.dll" no_namespace rename ("EOF", "EndOfFile ")
Using namespace std;
Int _ tmain (int argc, _ TCHAR * argv [])
{
: CoInitialize (NULL );
_ ConnectionPtr m_pConnection = NULL;
_ RecordsetPtr m_pRecordset = NULL;
M_pConnection.CreateInstance (_ uuidof (Connection ));
M_pRecordset.CreateInstance (_ uuidof (Recordset ));
_ Bstr_t strConnect = "Provider = SQLOLEDB.1; Password = 123456; Persist Security Info = True ;\
User ID = sa; Initial Catalog = testdb; Data Source = 192.168.1.3 ";
_ Bstr_t bstrSQL ("select * from testTable ");
Try
{
M_pConnection-> Open (strConnect, "", "", adModeUnknown );
M_pRecordset-> Open (bstrSQL, m_pConnection.GetInterfacePtr (), adOpenDynamic, adLockOptimistic, adshorttext );
_ Variant_t vstr, vuint;
While (! M_pRecordset-> EndOfFile)
{
Vstr = m_pRecordset-> GetCollect ("str ");
Vuint = m_pRecordset-> GetCollect ("uint ");
String str = (_ bstr_t) vstr. bstrVal;
Unsigned int uint = vuint. ulVal;
M_pRecordset-> MoveNext ();
}
M_pRecordset-> Close ();
}
Catch (_ com_error e)
{
Return 0;
}
If (m_pConnection-> State)
{
M_pConnection-> Close ();
}
: CoUninitialize ();
Return 0;
}