I'm use sql server 2014 and visual studio 2015 community I working on MFC DB Program(single document and OLE DB) but faced big trouble
Problem is when i change DB value in use by MFC button value isn't change in real time
when i pressed refresh button in editor, change value
how can i change value in real time?
below is code and picture
update button code
void CTouhouJGSView::OnBnClickedButtonUpdate()
{
// TODO: 여기에 컨트롤 알림 처리기 코드를 추가합니다.
CCommand<CDynamicAccessor> cmd;
CString strQuery = _T("UPDATE dbo.TouhouTable SET 능력 = 'ewrer' WHERE id = 1");
cmd.Open(m_pSet->m_session, strQuery, NULL);
cmd.Close();
AddAllRecord();
}
AddAllRecord() function
void CTouhouJGSView::AddAllRecord()
{
CString strTemp = _T("");
m_pSet->MoveFirst();
m_List.DeleteAllItems();
int i = 0;
do {
strTemp.Format(_T("%4d"), m_pSet->m_Id);
m_List.InsertItem(i, strTemp, 0);
m_List.SetItemText(i, 1, m_pSet->m_section);
m_List.SetItemText(i, 2, m_pSet->m_name);
m_List.SetItemText(i, 3, m_pSet->m_title);
m_List.SetItemText(i, 4, m_pSet->m_species);
m_List.SetItemText(i, 5, m_pSet->m_living);
m_List.SetItemText(i, 6, m_pSet->m_spell);
i++;
} while (m_pSet->MoveNext() == S_OK);
m_pSet->MoveFirst();
}
and program picture
enter image description here
EDIT : definition of m_pSet
#pragma once
#include "afxcmn.h"
#include "afxwin.h"
class CTouhouJGSSet;
class CTouhouJGSView : public COleDBRecordView
{
protected: // serialization에서만 만들어집니다.
CTouhouJGSView();
DECLARE_DYNCREATE(CTouhouJGSView)
public:
#ifdef AFX_DESIGN_TIME
enum{ IDD = IDD_TOUHOUJGS_FORM };
#endif
CTouhouJGSSet* m_pSet; //here
// 특성입니다.
public:
CTouhouJGSDoc* GetDocument() const;
EDIT2: class CTouhouJGSSet change part
//class CTouhouJGSSet : public CTable<CAccessor<CTouhouJGSSetAccessor> >
class CTouhouJGSSet : public CCommand<CAccessor<CTouhouJGSSetAccessor> >
{
......
HRESULT OpenRowset(DBPROPSET *pPropSet = NULL)
{
//HRESULT hr = Open(m_session, L"dbo.TouhouTable", pPropSet);
CString strSQL = _T("select * from dbo.TouhouTable");
HRESULT hr = Open(m_session, strSQL, pPropSet);
and OnInitialUpdate() function
void CTouhouJGSView::OnInitialUpdate()
{
,,,,,
COleDBRecordView::OnInitialUpdate();
AddColumn(); //additional function
AddAllRecord(); //additional function
}
EDIT 3: i say refresh button enter image description here
Find the way
m_pSetis filled with data. You have to refresh it or recreate beforeAddAllRecord();