Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How do I update members of my dynamic CRecordset

Status
Not open for further replies.

hansaplast

Programmer
Dec 17, 2001
61
NL
Hi,

I've created a dynamic connection to CDatabase object witch I bind to CRecordset.
How do I update the fields in my recordset?

NiceFunction()
{
CDatabase m_database;
CRecordset *p_dbSet;

// Create new recordset with connection to the database object
p_dbSet = new CRecordset(&m_database);

// Open the database
m_database.OpenEx(m_connectionStr);

// Get all from my parameters table
p_dbSet->Open(AFX_DB_USE_DEFAULT_TYPE,"SELECT * FROM parameters");

// Here I want to update my fiels from my recordset
// Function below does not exist but explains what I want to do
p_dbSet.SetField("MyField_in_Table", "Whatever I want to put in there");

// Close the database and delete the CRecordset
...
}

Tnx in advance,

Hansa
 
Hansa, have you used a tutorial to start working with CDatabase,CRecordset API?

If not you need to. If you have you missed the part the explains how to use CRecordset.

To modify rows you need a derived CRecordset with data members representing the columns. Then you use Edit(), set the member variables, then use Update() to store the changes. But you really need to look at the documentation in MSDN or use a tutorial or book or something.


-pete
 
But what, if I want to add a new column in a table?
Does it create a new data member in my CRecordset by itself?

What I use now is m_database.ExecuteSQL("SQL statement")
Only thing you must not forget is to requery your recordset so you have the current data available "p_dbSet->Requery()".

Hansa
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top