• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 141
  • Last Modified:

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.
0
simongod
Asked:
simongod
  • 4
  • 2
1 Solution
 
mjswartCommented:
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


0
 
simongodAuthor Commented:
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.
0
 
simongodAuthor Commented:
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?
0
Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

 
simongodAuthor Commented:
nope
0
 
simongodAuthor Commented:
if you want FREE pts answer this question, because I answered figured it out for myself.
0
 
inprasCommented:
Hi simonogod
Why don't U use DB Grid Activex Control I think it suits best for UR needs.
U need not worry about collecting from list and putting in edit control and again from edit control to list control.
Hope this helps
Regards
0
 
inprasCommented:
Thanks
0

Featured Post

Take Control of Web Hosting For Your Clients

As a web developer or IT admin, successfully managing multiple client accounts can be challenging. In this webinar we will look at the tools provided by Media Temple and Plesk to make managing your clients’ hosting easier.

  • 4
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now