Solved

CRecordset update record causing assertion failure

Posted on 2004-08-25
5
530 Views
Last Modified: 2013-11-20
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

0
Comment
Question by:raed_hasan
  • 3
5 Comments
 
LVL 44

Expert Comment

by:AndyAinscow
ID: 11893626
You posted the answer yourself.
error message said [Recordset is Readonly]

you CAN'T edit a readonly recordset.
0
 
LVL 44

Expert Comment

by:AndyAinscow
ID: 11893696
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?
0
 
LVL 2

Author Comment

by:raed_hasan
ID: 11899717
Ok, but what i need is how to disable Readonly property in CRecordset cause , i did the following code:

CDatabase dbConnection;
dbConnection.OpenEx("DSN=TestDB;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,Sql,CRecordset::none);//Assertion 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
0
 
LVL 44

Accepted Solution

by:
AndyAinscow earned 90 total points
ID: 11900103
The SQL statement begins with UPDATE - that is a command to manipulate the contents of a table/query.  It is NOT used to return records.  A statement like that is typically used as follows

dbConnection.ExecuteSQL(Sql);
0
 

Expert Comment

by:rpatna
ID: 11900750
try this:
CDatabase      database;

if(!database.Open(_T(<dsnName>),FALSE,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;
. . .

}
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
not able to insert into temp table 68 157
Separate into files by filename 12 76
sumNumber challenge 16 111
"Black Box" Testing of Control System Software 2 26
Introduction: Dynamic window placements and drawing on a form, simple usage of windows registry as a storage place for information. Continuing from the first article about sudoku.  There we have designed the application and put a lot of user int…
Introduction: Database storage, where is the exe actually on the disc? Playing a game selected randomly (how to generate random numbers).  Error trapping with try..catch to help the code run even if something goes wrong. Continuing from the seve…
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
Hi friends,  in this video  I'll show you how new windows 10 user can learn the using of windows 10. Thank you.

862 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

23 Experts available now in Live!

Get 1:1 Help Now