How do you update a record in MFC? 
Author Message
 How do you update a record in MFC?

I'm writing a data entry application that will initially use MS Access as
the DBase then we'll updgrade it to use MS SQL Server.  We'll be using
SQL commands to SELECT and UPDATE records.

My questions is - once I have the data of the record to update and the
user enters new information I need to update the record information.  
Each record has about 30 fields.

How do I structure my SQL Update command?  (I'm new to this so please
explain the best you can).

Thanks

Joe



Mon, 05 Jul 1999 03:00:00 GMT  
 How do you update a record in MFC?


[...]

Quote:
>My questions is - once I have the data of the record to update and the
>user enters new information I need to update the record information.  
>Each record has about 30 fields.

>How do I structure my SQL Update command?

My favorite approach is to write a string template-like thing for the
update and put it in an sprintf():

        // Get user information into local variables

        char sz[ lotsofroom ];
        sprintf(sz,"Update Table "
                        "Set (col1, col2, columns...) "
                        "to (%s, %d...)",
                user1, user2,...);

        // execute the sql update in sz

Hope this helps



Tue, 06 Jul 1999 03:00:00 GMT  
 How do you update a record in MFC?

MFC makes this a lot easier on the developer.  If you use ClassWizard to
create a CRecordset or CDAORecordset, MFC maps the fields from the database
to member variables of the class.  When you want to update a record with
code, call CMyRecordset::Edit(), change the value of the member variables
accordingly, and when you're ready call CMyRecordset::Update() to issue the
UPDATE statement.

For inserts, it's just as easy.  First call CMyRecordset::AddNew(), make
the modifications to the member variables, and call CMyRecordset::Update().

If you don't want to write the code, there is a way you can map fields of
the recordset directly into the controls on your screen.  Try creating a
simple application and in AppWizard select "Database View without file
support".  The documentation that comes with VC++ has a pretty good example
of how to do this in "Visual C++ Tutorials".  You can use ClassWizard to
add member variables for the controls on your screen, and then tell it
which field to map to.  I hope this gets you on your way.

Frank Hoffman
Legislative Service Center



Quote:
> I'm writing a data entry application that will initially use MS Access as
> the DBase then we'll updgrade it to use MS SQL Server.  We'll be using
> SQL commands to SELECT and UPDATE records.

> My questions is - once I have the data of the record to update and the
> user enters new information I need to update the record information.  
> Each record has about 30 fields.

> How do I structure my SQL Update command?  (I'm new to this so please
> explain the best you can).

> Thanks

> Joe



Fri, 16 Jul 1999 03:00:00 GMT  
 
 [ 3 post ] 

 Relevant Pages 

1. DAO3.60 - getting error 3260 when doing CDaoRecordset::Update

2. Doing stuff in DoModal() - Background thread updating UI problems

3. Updating A Changed Record

4. Record Update in Unix File like fupdate for MVS VSAM

5. Updating records on disk file

6. How to direct update a record in file ?

7. Updating records in files

8. Deleting and updating record

9. sorting, deleting, updating records in a binary file

10. can't update record

11. AddNew() Update() over writes either first or last record

12. Updating/Adding a new record that already exists in the db

 

 
Powered by phpBB® Forum Software