Link to home
Start Free TrialLog in
Avatar of simongod
simongod

asked on

how to save to a database

I can open a database and have its contents displayed inside of a listctrl.  When I dblclick on the listctrl the data is displayed in some edit controls.  When I click on another listbox more data is entered into another edit control.  All the data that is accumulated inside of the edit controls I want to save to the database inside of my listctrl.  Please tell me the easiest way to perform this.
Avatar of mjswart
mjswart

You could create an 'INSERT' or an 'UPDATE' sql query which you may then execute with CDatabase::ExecuteSQL

or better is to

use a CRecordset object have the recordset reflect the new listbox and call Update to update the datasource.

M


Avatar of simongod

ASKER

CDaoRecordset rec;

That is what I have for my recordset.  How might I use the update function?  To perform the updating.  I want it to take the date from the edit control fields (which is the new stuff) and update the database with it.  Then the changes should show up in the listctrl that shows the open database fields.
int nSel = m_database.GetNextItem(-1, LVNI_SELECTED);
      if(nSel != LB_ERR)
      {
            char szName[32];
            m_database.GetItemText(nSel, 0, szName, 32);
            int nSelection = m_selectblock.GetCurSel();
            CString szSelection;
            if(nSelection != LB_ERR)
            {
                  m_selectblock.GetText(nSelection, szSelection);
                  m_pblock.SetWindowText(szSelection);
            }
            rec.Edit();
            strcpy((char*)covVal.bstrVal, szSelection.GetBuffer(48));
            rec.SetFieldValue(_T("Name"), covVal);
            rec.Update();
      }


Is this what I have.  I looked at the parameters for the Update function and I really don't understand them.  What do I need to do to make this work?
nope
if you want FREE pts answer this question, because I answered figured it out for myself.
ASKER CERTIFIED SOLUTION
Avatar of inpras
inpras

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Thanks