Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2000 Forums
 SQL Server Development (2000)
 Edit throws exception

Author  Topic 

AskSQLTeam
Ask SQLTeam Question

0 Posts

Posted - 2003-06-17 : 08:08:46
Ramesh writes "Hi,
I have an application developed using MSDE as back end. I used ODBC classes CDatabase and CRecordset to interact with the database. I am opening a recordset and trying to edit a record. The Edit throws an error. I am opening editable recordset, but still when I checked with CanUpdate() and CanAppend(), it says the recordset is non-editable(i.e, CanUpdate() returns zero). The same code works properly when I used MSAccess as back end and JET driver.
Here is the code snippet:

outcome = pctbl->Open(CRecordset::dynaset, strTable, CRecordset::none);
if (outcome == 0)
{
// Free the record set
seterr(_T("could not open table")
return mdrOPEN_FAILED;
}

/////////////////////////////////////////////////////
// Edit a record or add a New Record
/////////////////////////////////////////////////////

TCHAR t[100];
_stprintf(t,_T("record count : %d, canupdate %d"),
pctbl->GetRecordCount(),pctbl->CanUpdate());


if (pctbl->IsEOF() || pctbl->IsDeleted()){//empty result
if (pctbl->CanAppend()) {
// Add new record
pctbl->AddNew();
} else {
seterr(_T("could not append new record with")
// Close the table and clean up
pctbl->Close();
return mdrADD_FAILED;
}
} else { // found extant record
try {
pctbl->Edit();
}catch(CDBException *e) {
AfxMessageBox((LPCTSTR)e->m_strError);
seterr(err);
AfxMessageBox((LPCTSTR)e-m_strStateNativeOrigin);
e->Delete();
return mdrUPDATE_FAILED;
}
Note: e->m_strError shows nothing when I tried to print the error.

Your answers are highly appreciated. I doubt there is some problem with the ODBC driver for the MSDE."
   

- Advertisement -