# include & lt; stdio.h>
# include & lt; Stdlib. H>
# include & lt; Afxdb. H>
Void main (int arg c, char * argv [])
{
Cstrings strSql;
CDatabase m_db;
M_db. Open (NULL);
CRecordset rs (& amp; M_db);
StrSql="select * from Student";
Printf (" student id \ t \ \ t t name gender \ t \ n ");
Rs. The Open (CRecordset: : forwardOnly, strSql, 0).
while(! Rs. IsEOF ())
{
Cstrings strNumber;
Cstrings strName;
Cstrings strSex;
Rs. GetFieldValue (Sno, strNumber);
Rs. GetFieldValue (" Sname ", strName);
Rs. GetFieldValue (" Ssex strSex);
Printf (" % s \ n \ \ t t % s % s ", strNumber, strName, strSex);
Rs. MoveNext ();
}
M_db. Close ();
}
CodePudding user response:
CodePudding user response:
CodePudding user response:
Our great god, please, have the person to help meCodePudding user response:
What is open (Null) open database, should not be the connection string, humble opinion, not how to use VCCodePudding user response:
The first thing to do: : CoInitialize (NULL);CodePudding user response:
See what mistakes or add exception handlingtry
{
//your ODBC database code
}
The catch (CException * pEx)
{
PEx - & gt; ReportError ();
PEx - & gt; The Delete ();
}
You built, not MFC engineering beginners do not recommend you use ODBC, ado example may have a look here,
CodePudding user response:
Didn't understand what you meanCodePudding user response:
The first thing to do: : CoInitialize (NULL); , what is the meaning of this sentenceCodePudding user response:
You look under the Debug database operations are successful? Such as Open call place to see the return value is correct?CodePudding user response:
Add a header file,# include & lt; Atlbase. H>
# include & lt; Afxoledb. H>
Add code:
CoInitialize (NULL);
//initialize the OLE libraries
if (! AfxOleInit ())
{
AfxMessageBox (IDP_OLE_INIT_FAILED);
return FALSE;
}
Give it a try