Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Sample code in VC++5.0 for data fetch using CRecordset -- URGENT

Status
Not open for further replies.

Striker99

Programmer
Oct 31, 2001
34
UA
I am trying my best to get into VC++ coding. At the moment, am trying to create a data fetch application using CDatabase and CRecordset classes. I seem to be missing things there because I keep receiving a message that says that the m_nFields attribute has not been set to the correct value. Following is the extract.

CDatabase DB;
CRecordset Recordset(&DB);

m_nFields=1;
BOOL bRtn=DB.Open("FILE", FALSE, TRUE, "ODBC;", TRUE );
Recordset.Open(AFX_DB_USE_DEFAULT_TYPE,"select CC7013MENUID from CS7013MENU",none);
DB.ExecuteSQL(strSQL);

Could somebody kindly advise at the earliest please?

Regards
 
I believe you need to call CDatabase::Open with the name of the ODBC source before you pass it to CRecordset.

Matt
 
Matt,
Thanks for your immediate help. The code pasted on the query has a statement wherein it opens the ODBC with the connection name FILE. Do you think there is something wrong with that statement?

Regards
 
I would try

CDatabase DB;
BOOL bRtn=DB.Open("FILE", FALSE, TRUE, "ODBC;", TRUE );
CRecordset Recordset(&DB);

//rest of code

Also make sure it is a registerd ODBC. If it is not, I belive you can use SQLCreateDataSource or SQLConfigDataSource api calls to do this.

One more thing to check is bRtn.

Matt
 
Hi,
How would one use the method OPEN in the CRecordSet MFC class? Ive been trying to create a CDatabase object and send it through the constructor of CRecordSet. But it seems that eventhough the Database open is successful, the error is thrown when the Recordset.Open method is called.

Any ideas why?

Regards
 
With CRecordset, it has to be a registered odbc source. However, with CDAORecordset, it does not. Calling open with DAO will pop up a dialog and allow you to select the database (i am 99% sure of that)

Matt
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top