Data Exchange
-
shouvik.d wrote:
The basic prob is how to update data without closing the Dlg Box.
Use a modeless dialog. http://msdn2.microsoft.com/en-us/library/hf0yazk7(vs.80).aspx[^]
You may be right
I may be crazy
-- Billy Joel --Within you lies the power for good, use it!!!
No i cant let a user access the SDI window when he/she is accessing the Dlg Box. I just used DDX but still until the Modal Dlg Box Closes I'm not able to invoke update to DB. how to do it:confused:
Success makes life easier. It doesn't make living easier. SH:)UVIK
-
shouvik.d wrote:
The basic prob is how to update data without closing the Dlg Box.
Use a modeless dialog. http://msdn2.microsoft.com/en-us/library/hf0yazk7(vs.80).aspx[^]
You may be right
I may be crazy
-- Billy Joel --Within you lies the power for good, use it!!!
This is what when the admin module has to be invoked. A passsword validation is done. Later the Admin window opens.
void CLibManView::OnAdmin() { Pass p1; p1.DoModal(); CString str,query,str1; int flag = 0; str=p1.m_pass; m_pSet->Close(); query = "Select * from Password where User='Admin'"; m_pSet->Open(CRecordset::dynaset, (LPCTSTR)query,CRecordset::none); m_pSet->MoveFirst(); while(!m_pSet->IsEOF()) { str1=m_pSet->m_Pass; if(str1==str) { flag=1; break; } m_pSet->MoveNext(); } if(0==flag) MessageBox("Wrong Password"); else { ad.DoModal(); m_pSet->Close(); char temp[2]; itoa(ad.type,temp,2); char locstat[2]; itoa(2,locstat,2); query="insert into book values('"+ad.m_Auto_Ac_No+"','"+ad.m_Add_Name+"','"+ad.m_Add_Auth+"',"+temp+","+ad.m_Add_Price+",'"+ad.m_Add_Date+"',"+locstat+")"; m_pSet->Open(CRecordset::dynaset,(LPCTSTR)query,CRecordset::none); m_pSet->Update(); m_pSet->Close(); } }
So without closing the Admin dlg box how to update data. also i'm getting an error. Syntax error in FROM clause on the above query. plz help
Man can acquire accomplishments or he can become an animal, whichever he wants. God makes the animals, man makes himself. G. C. Lichtenberg (1742-99), German physicist, philosopher. SH:)UVIK
-
No i cant let a user access the SDI window when he/she is accessing the Dlg Box. I just used DDX but still until the Modal Dlg Box Closes I'm not able to invoke update to DB. how to do it:confused:
Success makes life easier. It doesn't make living easier. SH:)UVIK
shouvik.d wrote:
No i cant let a user access the SDI window when he/she is accessing the Dlg Box.
Disable the SDI window while the dialog box is active. MFC simulates modal dialog boxes exactly in this way, creating a modeless dialog box from template, disabling main window if any, display the dialog, and reenable the main window after. Another possibility is to inform application from the modal dialog to perform the update. This way you don't have to wait the dialog to close, such as in
void CDlg::OnButtonClicked()
{
// gather data to update in a structure or class
CData data;
// ...static_cast(AfxGetApp())->updateDatabase(&data);
}and
void CSDIApp::updateDatabase(CData *pData)
{
// update in database using pData members
} -
shouvik.d wrote:
The basic prob is how to update data without closing the Dlg Box.
Use a modeless dialog. http://msdn2.microsoft.com/en-us/library/hf0yazk7(vs.80).aspx[^]
You may be right
I may be crazy
-- Billy Joel --Within you lies the power for good, use it!!!
plz help
Man can acquire accomplishments or he can become an animal, whichever he wants. God makes the animals, man makes himself. G. C. Lichtenberg (1742-99), German physicist, philosopher. SH:)UVIK
-
This is what when the admin module has to be invoked. A passsword validation is done. Later the Admin window opens.
void CLibManView::OnAdmin() { Pass p1; p1.DoModal(); CString str,query,str1; int flag = 0; str=p1.m_pass; m_pSet->Close(); query = "Select * from Password where User='Admin'"; m_pSet->Open(CRecordset::dynaset, (LPCTSTR)query,CRecordset::none); m_pSet->MoveFirst(); while(!m_pSet->IsEOF()) { str1=m_pSet->m_Pass; if(str1==str) { flag=1; break; } m_pSet->MoveNext(); } if(0==flag) MessageBox("Wrong Password"); else { ad.DoModal(); m_pSet->Close(); char temp[2]; itoa(ad.type,temp,2); char locstat[2]; itoa(2,locstat,2); query="insert into book values('"+ad.m_Auto_Ac_No+"','"+ad.m_Add_Name+"','"+ad.m_Add_Auth+"',"+temp+","+ad.m_Add_Price+",'"+ad.m_Add_Date+"',"+locstat+")"; m_pSet->Open(CRecordset::dynaset,(LPCTSTR)query,CRecordset::none); m_pSet->Update(); m_pSet->Close(); } }
So without closing the Admin dlg box how to update data. also i'm getting an error. Syntax error in FROM clause on the above query. plz help
Man can acquire accomplishments or he can become an animal, whichever he wants. God makes the animals, man makes himself. G. C. Lichtenberg (1742-99), German physicist, philosopher. SH:)UVIK
-
shouvik.d wrote:
No i cant let a user access the SDI window when he/she is accessing the Dlg Box.
Disable the SDI window while the dialog box is active. MFC simulates modal dialog boxes exactly in this way, creating a modeless dialog box from template, disabling main window if any, display the dialog, and reenable the main window after. Another possibility is to inform application from the modal dialog to perform the update. This way you don't have to wait the dialog to close, such as in
void CDlg::OnButtonClicked()
{
// gather data to update in a structure or class
CData data;
// ...static_cast(AfxGetApp())->updateDatabase(&data);
}and
void CSDIApp::updateDatabase(CData *pData)
{
// update in database using pData members
}firstly thr is no CData class only CDatabase is available. and plz can u throw a bit more light into this. I'm an amateur n very new to VC++.
There are only two kinds of people who are really fascinating-people who know absolutely everything, and people who know absolutely nothing. Oscar Wilde (1854-1900) SH:)UVIK
-
One method is to do what Cristian Amarie said above. Another is to move the SQL code into the dialog itself.
You may be right
I may be crazy
-- Billy Joel --Within you lies the power for good, use it!!!
But i am not able to access the m_pSet-> variable in the Dialog Box. So how can i update the fields which can be accessed through only the REcordset object m_pSet.
There are only two kinds of people who are really fascinating-people who know absolutely everything, and people who know absolutely nothing. Oscar Wilde (1854-1900) SH:)UVIK
-
firstly thr is no CData class only CDatabase is available. and plz can u throw a bit more light into this. I'm an amateur n very new to VC++.
There are only two kinds of people who are really fascinating-people who know absolutely everything, and people who know absolutely nothing. Oscar Wilde (1854-1900) SH:)UVIK
I mean CData as a placeholder for your data, you should implement it yourself as a mean to communicate between the dialog and the application object. In this way, you can collect data from the dialog, declare and fill a structure or class (this is CData) and pass it to the application (or whatever other object you want to delegate for operating in database).
-
But i am not able to access the m_pSet-> variable in the Dialog Box. So how can i update the fields which can be accessed through only the REcordset object m_pSet.
There are only two kinds of people who are really fascinating-people who know absolutely everything, and people who know absolutely nothing. Oscar Wilde (1854-1900) SH:)UVIK
-
plz help
Man can acquire accomplishments or he can become an animal, whichever he wants. God makes the animals, man makes himself. G. C. Lichtenberg (1742-99), German physicist, philosopher. SH:)UVIK
You got the help already. 1. Pass the database objects as pointers (or references) to the dialog and do the DB work directly inside dialog. 2. Use a messaging mechanism (not especially Windows messages, although could work too) to signal back from dialog to the object that contain your variable m_pRecSet to "do the DB work". 3. Use a separate class that does the DB work, declared by the application object, main window object or where you see this fit, and use a messaging mechanism back and forth to/from this object to any object that require "DB services". Whenever a DB operation needs to be performed, you must have the means to retrieve and use the DB object, either directly (1), via accesors of other objects (2), or using a convenient object that encapsulates the DB services (3). The solution is up to you, as well as what kind of services can be performed - direct brute queries formatted elsewhere, or using more specialized business logic oriented derived classes. I suggest you to implement a hierarchy like: Connection Statement StatementWithResults Recordset StoredProcedure ... (whatever you like) as well as your business objects which can derive from StatementWithResults (1 row in a table) or Recordset for collections.