Home > Software engineering >  Please everyone a great god help small woman, I use the vc call Ssever2008 SQL database appears belo
Please everyone a great god help small woman, I use the vc call Ssever2008 SQL database appears belo

Time:10-25

C + + editor program is as follows, there is no problem, then I click on the run after chose me to access the data source, after first appeared in figure 1, I ordered after the jump in figure 2, really don't know how, please, a great god,
 # 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 me

CodePudding user response:

What is open (Null) open database, should not be the connection string, humble opinion, not how to use VC

CodePudding user response:

The first thing to do: : CoInitialize (NULL);

CodePudding user response:

See what mistakes or add exception handling
 try 
{
//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 mean

CodePudding user response:

The first thing to do: : CoInitialize (NULL); , what is the meaning of this sentence

CodePudding 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
  • Related