?
Solved

SQL Server Database Connectivity with MFC

Posted on 1999-08-19
3
Medium Priority
?
410 Views
Last Modified: 2013-11-20
Hi everybody,

My question is in relation with the connectivity
with SQL Server Database. I want to connect my SQL
Server database with my MFC Application. I am able
to connect Access database smoothly but what is to
be done for SQL Server.

Please see the followings :

1) My project is a SDI application.
2) I have chosen "Header Files Only" in AppWizard
   Database Support screen.
3) I am not deriving any class from CDatabase. Only
   in OnNewDocument() of Document class I am defining
   an object of CDatabase.
4) I am deriving table specific class from CRecordset
   and in OnNewDocument() associating this with above
   CDatabse Class.
5) Ultimately I am using the CRecordset class in my
   Dialog taking the ptr of CRecordset class.

Considering the above please give me solution with
suitable example.

Thanks,
0
Comment
Question by:majorjohn
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 1

Accepted Solution

by:
anoops earned 400 total points
ID: 1314363
A comment..
Just like you are not deriving from CDatabase, It'd be great if you use the CRecordset directly. If yoy derive from CRecordset and make it table specific then you are making it less flexible( You wont be able to do any kinda "JOIN")..
try the following code..

      CDatabase dbMine;
      if( dbMine.OpenEx(  _T(  "DSN= MYDATA;"  )  )  )
              {
                 CRecordset tblTest( &dbMine );
                 CString csSql = "Select * from MyTable";
         if( !tblTest.Open( CRecordset::dynaset, csSql  ))
                {
                  TRACE0( "Table open failed" );
          return ;
                };
              }

0
 
LVL 1

Author Comment

by:majorjohn
ID: 1314364
anoops

With ur answer I had to do some extra R&D and achieved the result. Anyway U answered me in right time. Can u leave ur email address. So in any future problem I can contact u directly.

Thanks
0
 
LVL 1

Expert Comment

by:anoops
ID: 1314365
Yup..with pleasure..:)) use..

anoops@hiso.honeywell.com
or
anoop_sreedhar@hotmail.com
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

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 …
Introduction: Dialogs (2) modeless dialog and a worker thread.  Handling data shared between threads.  Recursive functions. Continuing from the tenth article about sudoku.   Last article we worked with a modal dialog to help maintain informat…
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.
How to fix incompatible JVM issue while installing Eclipse While installing Eclipse in windows, got one error like above and unable to proceed with the installation. This video describes how to successfully install Eclipse. How to solve incompa…

719 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