Solved

How to fully access SQL server database with VC++5.0?

Posted on 1998-08-20
1
340 Views
Last Modified: 2010-04-01

I built a SQL server database with MS-SQL 6.5. I want to use MS VC++ 5.0 to access the database, such as, add, retrieve, delete records and etc.

So, after I built the database within MS SQL server "Enterprise Manager", I setup "ODBC database source" within "ODBC(32bit)" in Control Panel. Then, I add a MFC class "Myrecord" based on "CRecordSet".

At first, in my VC++5.0 source code, I use "CRecordSet::Open()" to open the database (No any parameters in "Open()", as the MS example shows). Then, I use "CRecordSet::AddNew()" or "CRecordSet::Edit()"  and "CRecordSet::Update()" to add or modify records in the database. However, right after the program executes "AddNew()" or "Edit()", there is a dialog box poped up: "Recordset is read-only".

So, I can't add or modify records in the database that I built and setup. Is the problem within SQL server database, or within the VC++ problem? From the VC++ help, I know that using "CRecordSet:Open()" (without any parameters) mean that the opened database can be fully accessed. However, why did it show "RecordSet is read-only"?

BTW, when I built my VC++ project with the "File->New" MFC AppWizard (multiple Document), in the step 2 of 6, I choosed "Header files only".

Now, I can only retrieve the records in the database but not add or delete. However, I am eager to fully access the database. Could you please help me figure out the problem?

Thank you very much!

--
Dataxx
 
0
Comment
Question by:dataxx
1 Comment
 
LVL 1

Accepted Solution

by:
softev earned 200 total points
ID: 1170785
Dataxx,

Look into creating a CDatabase object and passing into the
constructor of your CRecordSet object during construction time.
You'll be able to set properties on the CDatabase object that
allow for read/write...

Softev

0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Unlike C#, C++ doesn't have native support for sealing classes (so they cannot be sub-classed). At the cost of a virtual base class pointer it is possible to implement a pseudo sealing mechanism The trick is to virtually inherit from a base class…
Article by: SunnyDark
This article's goal is to present you with an easy to use XML wrapper for C++ and also present some interesting techniques that you might use with MS C++. The reason I built this class is to ease the pain of using XML files with C++, since there is…
The goal of the tutorial is to teach the user how to use functions in C++. The video will cover how to define functions, how to call functions and how to create functions prototypes. Microsoft Visual C++ 2010 Express will be used as a text editor an…
The viewer will learn how to user default arguments when defining functions. This method of defining functions will be contrasted with the non-default-argument of defining functions.

867 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

15 Experts available now in Live!

Get 1:1 Help Now