Add/Update database with ADO Data control
- From: Sohail <sohail9697@xxxxxxxxx>
- Date: 14 May 2007 23:19:34 -0700
Hi,
I have an SDI application that is using dialog for displaying data
with MSHFlexGrid.On the same dialog, there are options for the user
to
add the records. There is an activex control ADO data control that is
being used to communicate with the db.
now with the given set of code, I am trying to provide the connection
string and SQL query to the ado data control and then activate the
connection and have used the refresh( ) method to actually get the db
table affected.
-------------------------------------------------------
void CSingleDocDialogView::OnAdd()
{
// TODO: Add your control notification handler code here
UpdateData(TRUE);
CString connStr = "Provider=MSDataShape;Data
Provider=Microsoft.Jet.OLEDB.4.0;Data Source=G:\\VC\\WorkDB\
\Fynanse.mdb;Persist Security Info=False";
//m_dbvariable is a variable of type ado data control for doing
operations
m_dbvariable.SetConnectionString(connStr);
m_dbvariable.SetMode(3); //read write mode
m_dbvariable.SetCursorType(0); //dynamic type
m_dbvariable.SetRecordSource("insert into Accounts
(AccountID,
Description) VALUES ('"+m_AccountCode+"','"+AccountName+"')");
//m_dbvariable.EnableConnections();
//m_dbvariable.SetEnabled(TRUE);
m_dbvariable.Refresh();
------------------------------------------------------
when the refresh( ) method gets executed, the application has a
message like operation is not allowed on a closed object...but then
when I relaunch the application, it has actually inserted the record
in the table.
so my problem is:
1. Why is this message being displayed, even if I remove the comments
from statements like enableconnections( ) or setenabled( ) OR there
is
something else to be done?
2. I could not find any kind of open( ) method for this activex
control. Is there any other way?
3. In general, when we use an activex control, how to see the
detailed
help for the functionality of its methods?
regards
Sohail
P.S. It had been posted to vc.database group but yet to find a reply.
.
- Follow-Ups:
- Re: Add/Update database with ADO Data control
- From: saxenavaibhav17
- Re: Add/Update database with ADO Data control
- Prev by Date: Re: ADO OpenSchema( adSchemaPrimaryKeys , ...)
- Next by Date: ADO: display limited records
- Previous by thread: Re: ADO recordset doesn't see DB changes
- Next by thread: Re: Add/Update database with ADO Data control
- Index(es):
Relevant Pages
|
|