Home > Back-end >  Based on VC6, ACCESS database connection using ADO method, C language
Based on VC6, ACCESS database connection using ADO method, C language

Time:10-02

Function description: click on the button, connect to the database, and shows the database records; ! Problem of -- -- -- -- -- -- -- -- -- -- -- -- -- -- --! : now compiled through, no problem, but click on the button, the software prompts "this application has requested the runtime to terminate it in an lead way"
Key code is as follows:
[code=c + +]
Void CAdoDlg: : OnBtnQuery ()
{
CoInitialize (NULL);
_ConnectionPtr pConn (__uuidof (Connection));
_RecordsetPtr pRst (__uuidof (you));
PConn. CreateInstance (" ADODB. Connection ");
PConn - & gt; Open (" Provider=Microsoft. Jet. The OlEDB. 4.0; Data Source=d: \ bit MDB ", ""," ", adConnectUnspecified);
PRst=pConn - & gt; Execute (" select * from One ", NULL, adCmdText);
//read the database contents and displayed in the "IDC_LIST1 controls inside
"while(! PRst - & gt; RsEOF)
{
((CListBox *) GetDlgItem (IDC_LIST1)) - & gt; AddString (pRst (_bstr_t) - & gt; V_lname GetCollect (" "));
PRst - & gt; MoveNext ();
}
PRst - & gt; Close ();
PConn - & gt; Close ();
PRst. Release ();
PConn. Release ();
CoUninitialize ();
}
[/code]
  • Related