raed_hasan
asked on
CRecordset update record causing assertion failure
Dear:
I have problem when try to update a record using CRecordset , that when make
TRY ...CATCH and error message said [Recordset is Readonly],
what I did i build MFC Application then , I added new Class derived from
CRecordset and did the following code inside OnInitDialogue:
CClients dbRecord;// CClient my derived class from CRecordset
dbRecord.Edit();//here Debug assertion failure occurred;
dbRecord.m_Address = "FL";
...
....
..
dbRecord.Update();
any ideas?
Regards
I have problem when try to update a record using CRecordset , that when make
TRY ...CATCH and error message said [Recordset is Readonly],
what I did i build MFC Application then , I added new Class derived from
CRecordset and did the following code inside OnInitDialogue:
CClients dbRecord;// CClient my derived class from CRecordset
dbRecord.Edit();//here Debug assertion failure occurred;
dbRecord.m_Address = "FL";
...
....
..
dbRecord.Update();
any ideas?
Regards
Is your recordset based on a query? If yes then your query may not be editable (groups/sums information, joins to other tables, there are a number of reasons why it might not be editable).
Is the database itself readonly? Do you only have read allowances to the table in the database? Is the database on a drive/directory you don't have write permissions for?
Is the database itself readonly? Do you only have read allowances to the table in the database? Is the database on a drive/directory you don't have write permissions for?
ASKER
Ok, but what i need is how to disable Readonly property in CRecordset cause , i did the following code:
CDatabase dbConnection;
dbConnection.OpenEx("DSN=T estDB;uid= sa;pwd=");
//dbConnection.Open("ODBC; DSN=SQL Server;UID=sa;PWD=");
CRecordset dbRecord(&dbConnection);
//SQL Select Statement
char Sql[1024] = "UPDATE Clients SET Counter = 1 WHERE ClientID = '";
strcat(Sql,"000000000402") ;
strcat(Sql,"'");
TRY
{
dbRecord.Open(CRecordset:: snapshot,S ql,CRecord set::none) ;//Asserti on Failure here
//in Assertion Message Box ( File Name : dbCore.cpp) (Line: 3282)
}
CATCH(CDBException,e)
{
char s[256]="\0";
strcpy(s,e->m_strError);
}
END_CATCH
Regards
CDatabase dbConnection;
dbConnection.OpenEx("DSN=T
//dbConnection.Open("ODBC;
CRecordset dbRecord(&dbConnection);
//SQL Select Statement
char Sql[1024] = "UPDATE Clients SET Counter = 1 WHERE ClientID = '";
strcat(Sql,"000000000402")
strcat(Sql,"'");
TRY
{
dbRecord.Open(CRecordset::
//in Assertion Message Box ( File Name : dbCore.cpp) (Line: 3282)
}
CATCH(CDBException,e)
{
char s[256]="\0";
strcpy(s,e->m_strError);
}
END_CATCH
Regards
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
try this:
CDatabase database;
if(!database.Open(_T(<dsnN ame>),FALS E,FALSE,_T ("ODBC;")) )
{
return 0; // if DataBase not opened
}
CRecordset recSet(&database);
CString sqlCmd;
sqlCmd = "SELECT * ";
sqlCmd += "FROM BIT_SYNC WHERE SetupName = ";
sqlCmd += "'";
sqlCmd += setupName;
sqlCmd += "'";
if(!recSet.Open( CRecordset::forwardOnly,_T ( sqlCmd ) ))
{
if (database.IsOpen())
database.Close();
return FALSE;
}
CDBVariant dbVariant;
while( !recSet.IsEOF( ) )
{
index = 1;
recSet.GetFieldValue( index++, dbVariant );
rBitSyncData->source = dbVariant.m_chVal;
. . .
}
CDatabase database;
if(!database.Open(_T(<dsnN
{
return 0; // if DataBase not opened
}
CRecordset recSet(&database);
CString sqlCmd;
sqlCmd = "SELECT * ";
sqlCmd += "FROM BIT_SYNC WHERE SetupName = ";
sqlCmd += "'";
sqlCmd += setupName;
sqlCmd += "'";
if(!recSet.Open( CRecordset::forwardOnly,_T
{
if (database.IsOpen())
database.Close();
return FALSE;
}
CDBVariant dbVariant;
while( !recSet.IsEOF( ) )
{
index = 1;
recSet.GetFieldValue( index++, dbVariant );
rBitSyncData->source = dbVariant.m_chVal;
. . .
}
error message said [Recordset is Readonly]
you CAN'T edit a readonly recordset.