Solved

How to access records from ODBC in VC++(MFC)???

Posted on 2002-05-15
20
281 Views
Last Modified: 2013-11-20


   I am building a instant messenger in VC++

   My problem is that i can access the records from the database using CRecordSet as shown:::
     rs.Open(CRecordset::dynaset,_T("Select EmpLogin from EmpApplList where AppLogin = '"+(((CVidserverDlg*)m_pWnd)->m_LoginInfo[0])+"'"));

     while(!rs.IsEOF() )
      {
        m_EmpNames[i] = rs.m_EmpLogin ;    
        wsprintf(outtext,"%s  %d",m_EmpNames[i],i);
        AfxMessageBox(outtext);
        i++;    
        rs.MoveNext();
      }
The query is getting executed properly but the problem is that i can't see the value in rs.m_EmpLogin where rs is an object of CRecordSet  
I think that the values are not getting bound to the database fields????
i will be thankful for prompt replies

   urs sincerely
india_bb
0
Comment
Question by:india_bb
  • 7
  • 5
  • 4
  • +2
20 Comments
 
LVL 6

Expert Comment

by:Triskelion
ID: 7012981
Are you sure there is a good open to the recordset?

[...assuming the rs.m_EmpLogin is a CString...]
What data type is the m_EmpNames array?
If it is an array of CString, you may need to call GetBuffer(0) inside the wsprintf
wsprintf(outtext,"%s  %d",m_EmpNames[i].GetBuffer(0),i);

If it's not a CString array, you will have data type issues when assigning the rs.m_EmpLogin to it.

0
 

Author Comment

by:india_bb
ID: 7013045
hello Mr Triskelion

    I did the thing which u said 'coz i am using CString array only ....thanx for it

The problem doesn't get solved ...
actually the loop executes as many times as it finds records in the database in that table but the value doesn't get bound to  the variable of the CRecordSet class
that is rs.m_EmpLogin


Prompt reply will be highly appreciative
thanx


0
 
LVL 6

Accepted Solution

by:
Triskelion earned 50 total points
ID: 7013054
Did you check your DoFieldExchange() to make sure it's returning the data type you expect?
Is the m_EmpLogin listed as a CString in the header file?

If you AfxMessageBox(m_EmpLogin) in the loop (without usint wsprintf()), what happens?
0
 
LVL 23

Expert Comment

by:Roshan Davis
ID: 7013062
Derive a class from CRecordset, MFC will ask the DSN Name, so u just select it.

Then MFC will create a class containing the members with  prefix "m_" .


GOOD LUCK
0
 

Author Comment

by:india_bb
ID: 7013077




Hello friend do u have a yahoo Id or hotmail id so that we can chat

   thanx
0
 
LVL 23

Expert Comment

by:Roshan Davis
ID: 7013078
Sorry, I 'm in office, u can comment out here.....
messengers are restricted here....

Have u tried my comment ?

regards


Roshmon
0
 

Author Comment

by:india_bb
ID: 7013099




Hello friend do u have a yahoo Id or hotmail id so that we can chat

   thanx
0
 
LVL 23

Expert Comment

by:Roshan Davis
ID: 7013104
Sorry, I 'm in office, u can comment out here.....
messengers are restricted here....

Have u tried my comment ?

regards


Roshmon
0
 

Author Comment

by:india_bb
ID: 7013127




Hello friend do u have a yahoo Id or hotmail id so that we can chat

   thanx
0
 
LVL 23

Expert Comment

by:Roshan Davis
ID: 7013134
Hello Friend,

    I'm in OFFICE. There is no messengers allowded...

Regards

Roshmon
0
What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

 

Author Comment

by:india_bb
ID: 7013135
Hello
Mr Triskelion do u have a yahoo Id or hotmail id so that we can chat

  thanx
0
 
LVL 4

Expert Comment

by:pagladasu
ID: 7014053
do something like:
rs.GetFieldValue(0,m_EmpNames[i]);
instead of:
m_EmpNames[i] = rs.m_EmpLogin ;    
0
 

Expert Comment

by:vcppmfc
ID: 7015733
Hi

>> m_EmpNames[i] = rs.m_EmpLogin ;    

I am not sure about the data type  rs.m_EmpLogin returns.
Can you pl mention the data type rs.m_EmpLogin belong while creating this table.
How you have configured your DSN ?
Which ODBC driver your DSN is configured to ?

I faced similary problem like i was not able get numeric values from the table even through query executed properly and i configured my DSN with Microsoft ODBC for Oracle and i was able to get both the string values and numeric values.
0
 
LVL 6

Expert Comment

by:Triskelion
ID: 7016013
Hi vcppmfc, welcome to EE.

All of the experts here, for the most part have learn from other experts as to the proper etiquette
for posting answer.

Please don't lock questions especialy when the questioner has asked that the question not be locked.

An answer should not be posted as an answer, if other experts have previously posted possible answers
as comments, and/or have already made contributions to the question.

There are many experts who never post answers as answer.  Instead, they post their answers as comments.

If you read the following link, you'll see why this is the preferred method for many of our valued experts,
including myself.

http://www.experts-exchange.com/jsp/cmtyQuestAnswer.jsp

Hi india_bb:
Feel free to click the [Reject Answer] button near vcppmfc's response, even if it seems like
a good answer.
Doing so will increase your chance of obtaining additional input from other experts.  Later, you can
click the [Select Comment as Answer] button on any response.
0
 

Expert Comment

by:vcppmfc
ID: 7017964
Hi Triskelion

What you say is correct.Sorry for the inconvenience.
0
 

Expert Comment

by:vcppmfc
ID: 7017965
Hi india_bb:

For the time beign you can take my answer as an comment.Do you have any thing to say about my comment i have already posted ?
0
 

Expert Comment

by:vcppmfc
ID: 7020788
waiting for you feedback pl
0
 

Author Comment

by:india_bb
ID: 7037582
Thanx to all of the experts who particiapted in this quest

I got the answer
actually i need to make a different CRecordSet Object class for diffferent tables in my database

The mistake i did was  that i was using same CRecordSet for different tables
hence it was giving such wage replies

My special thanx to mr Triskelion for his kind help
0
 

Author Comment

by:india_bb
ID: 7037589
Thanx to all of the experts who particiapted in this quest

I got the answer
actually i need to make a different CRecordSet Object class for diffferent tables in my database

The mistake i did was  that i was using same CRecordSet for different tables
hence it was giving such wage replies

My special thanx to mr Triskelion for his kind help
0
 

Expert Comment

by:vcppmfc
ID: 7041798
hi india_bb

If you are using SELECT * from table query then single CRecordset object is enough.But if you are using UPDATE SQL Statements then for each table you should CRecordset object seperately and each fields should be binded.This how i solve similar problem.
0

Featured Post

How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
Question regarding Copy/Paste 16 86
Unix / Linux grid computing 5 126
conditional code and condition difference 9 65
Problem to event 3 49
In this article, I'll describe -- and show pictures of -- some of the significant additions that have been made available to programmers in the MFC Feature Pack for Visual C++ 2008.  These same feature are in the MFC libraries that come with Visual …
Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…

708 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now