Chapter 20. Updating Data Sources

In this chapter, you'll build on what you learned about accessing a database via ODBC in the previous chapter, and try your hand at updating the Northwind Traders database through the same mechanism.

By the end of this chapter, you will have learned about:

  • Database transactions

  • How to update a database using recordset objects

  • How data is transferred from a recordset to the database in an update operation

  • How to update an existing row in a table

  • How to add a new row to a table

Update Operations

When you are just writing code to view information from a database, the only issue is whether you are authorized to access the data. As long as the database has the right kind of access protection, the data in the database is safe. As soon as you start writing code to update a database, it's quite another kettle of fish. Because you are altering the contents of the database, such modifications could destroy the integrity of the database and make nonsense of the contents of a table, or even make it unusable. You always need to take great care to test your code properly with a test database before letting it loose on the real thing.

A database update typically involves modifying one or more fields in a row in an existing table, modifying an order quantity for instance, or adding a new row—a new order perhaps in the context of the Northwind database. You'll be developing examples of both of these, but first, consider the implications.

Most of the complications that can ...

Get Ivor Horton's Beginning Visual C++® 2005 now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.