• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 196
  • Last Modified:

Help ! ... Database or object is read-only !

Hi !

I have a program which uses DAO to connect to a database.
In this database I have two different tables from where I read/write data.

Now to the problem. When I used only one table in my database I had no problems writing to the database, but now after adding the other table I can't write to it anymore(reading is possible).
When I do 'm_pSet->Edit()' I get the error message "Can't update. Database or object is read-only".
Maybe I'm the one who's slow here but I can't see any changes between my old 'one-table' set-file and my new 'two-table' set-file that would make it 'read-only'

Help appriciated.
1 Solution
When U open two tables in a sigle recordset class U have to perform join so that when U open UR recordset will know what to Open means depending on what constraint see the article below


if U do what ever said I U won't get the error

Hope this helps
cbjorkmanAuthor Commented:
As far as I know they should be joined  since I'm able to get data from both tables. To get the data I use the following:

var = m_pSet->m_ReceptNrW;      
str = var.bstrVal;            
m_Nr = str;

Where var is declared as COleVariant and str as string. m_Nr is an EditBox.

It's just when I try to write to the Database that I get the 'Can't Upd..' error message.


// start code

CDaoDatabase *db = new CDaoDatabase ();

m_db->Open ("<your JET/ODBC database>");

CDaoRecordset *rs;

rs = new CDaoRecordset;

// end code

after this step, you should decide which tables, and which fields to use. If your tables can be linked via a common field, set an SQL string which can be done with JOIN statement. If not so, you can not jo├Żn tables, your work must be completed seperately.

// start code
CString sql;
sql = "SELECT * FROM tb1, tb2 INNER JOIN
 tb1.f1 ON tb2.f1 WHERE ....";
// prepare this sql statement for your req.s

rs->Open (sql,  other security parameters....);

// end code

after this step you should be able to edit this recordset.

I hope this helps

Featured Post

Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now