Link to home
Start Free TrialLog in
Avatar of chikersal
chikersal

asked on

odbc data source

Sir,

   My question is about odbc data source

  i created a datasource called "pubs"
 
 now i use CDatabase to connect to this data source
 but since i am not using document-view architecture ihave to connect explicitly by aclling CDatabase::Open function, but the source whcih i am refering to has not described this function but i tried this function on my own liek this below:

  CDatabase::Open("ODBC;DSN=pubs");
 i have left all other parameters to null,
but its not working

then i used CDatabase::OpenEx() in the same manner
even that is not working properly

and after that i created an instance of CRecordset like this below:

CRecordset rec(&db); // i gave the address of CDatabase object

now had i been using doc view architecture, the framework would have called CRecordset::GetConnect to get the connect string and CRecordset::GetSqlDefault ( if i am not wrong may be its CRecordset::GetDefaultSQL) to get the sql query string, but since i am not using doc view

i called explicitly CRecordset::Open(AFX_DB_USE_DEFAULT_SETTING,"select * from employees");

the first is the default value which says that the recordset has to be a snapshot and the second is the query itself but even this is not working

and i also want to know that even if i dont use doc view architecture and say i move to the next record by calling CRecordset::MoveNext, will mfc on its own call CRecordset::DoFieldExchange() with CFieldExchange object pointer as a parameter or does it to do it only in case of doc view. If its only in case of doc view then i have to construct an object manually of Class CFieldExchange. Thi class is very important bcos it encapsulates exchange of data between CDatabase and CRecordset. So how would i create this class.

Pls i know my question is lengthy but u see ia ma so frustrated bcos i know the funda but i am not being able to put it to use practically

so pls give me the proper code pls pls pls

another point is if say i use CDatabase::Open() with username and password

how will i do it bcos my book says like this

CDatabase::Open("ODBC;DSN=pubs;UID=admin;PWD=password");
 is admin and password here are variables, i mean how can we mention a variable name inside a string, bcos insoide string it is being considered a part of a string, not a variable name
ASKER CERTIFIED SOLUTION
Avatar of Triskelion
Triskelion
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Secondly, what do you mean by "It's not working"?
Do you get a return value of true from the call to Open()?
   If so, the database is open

Does a dialog box pop up?
   If so, you're not giving it enough parameters


Avatar of chikersal
chikersal

ASKER

so after using this say is CDatabse::Open() works and then will i create object of CRecordset like this

CRecordset:: rec(&db) ( where db is an instance of CDatabase) and use CRecordset::Open() like this below:

CRecordset::Open(AFX_DB_USE_DEFAULT_TYPE,"select * from pubs");

is it correct and if yes then ofcourse it will generate a recordset which will be encapsulated by CDatabase. Then if i have to movethe current record from CDatabase to CRecordset i make use of CFieldExchange. My point will mfc on its own call CRecordset::DoFieldExchange() with the address of CFieldExchange object. I know in cse of doc view its this function is called by the framework. What i want to know is that if i dont use doc view, then also will it be called on its own or do i have to call CRecordset::DoFieldExchange(). bcos if i have to call this function, then how will i create the object of CFieldExchange.
The DoFieldExchange will be called automatically by the framework.

Did you use the ClassWizard to build the class?
If not, you should.  It handles all of the mapping and extending for you.
chikersal,

You have a large number of questions have been open for some time, and our records show you logged in as recently as today. Please resolve them appropriately as soon as possible. Continued disregard of your open questions will result in the force/acceptance of a comment as an answer; other actions affecting your account may also be taken. I will revisit these questions in approximately seven (7) days.

https://www.experts-exchange.com/jsp/qShow.jsp?qid=11443178
https://www.experts-exchange.com/jsp/qShow.jsp?qid=11964778
https://www.experts-exchange.com/jsp/qShow.jsp?qid=12043279
https://www.experts-exchange.com/jsp/qShow.jsp?qid=11564958
https://www.experts-exchange.com/jsp/qShow.jsp?qid=20104338
https://www.experts-exchange.com/jsp/qShow.jsp?qid=20104344
https://www.experts-exchange.com/jsp/qShow.jsp?qid=20105195
https://www.experts-exchange.com/jsp/qShow.jsp?qid=20107021
https://www.experts-exchange.com/jsp/qShow.jsp?qid=20117736
https://www.experts-exchange.com/jsp/qShow.jsp?qid=20123376
https://www.experts-exchange.com/jsp/qShow.jsp?qid=20128779
https://www.experts-exchange.com/jsp/qShow.jsp?qid=11146525
https://www.experts-exchange.com/jsp/qShow.jsp?qid=11559878
https://www.experts-exchange.com/jsp/qShow.jsp?qid=11540439
https://www.experts-exchange.com/jsp/qShow.jsp?qid=20158555
https://www.experts-exchange.com/jsp/qShow.jsp?qid=20174325
https://www.experts-exchange.com/jsp/qShow.jsp?qid=20176309
https://www.experts-exchange.com/jsp/qShow.jsp?qid=20177269
https://www.experts-exchange.com/jsp/qShow.jsp?qid=20183746
https://www.experts-exchange.com/jsp/qShow.jsp?qid=20184309
https://www.experts-exchange.com/jsp/qShow.jsp?qid=20188568
https://www.experts-exchange.com/jsp/qShow.jsp?qid=20260766
https://www.experts-exchange.com/jsp/qShow.jsp?qid=20260773
https://www.experts-exchange.com/jsp/qShow.jsp?qid=20262003

Thanks,

Netminder
Community Support Moderator
Experts Exchange
Force/accepted by

Netminder
Community Support Moderator
Experts Exchange