Error "Recordset is read-only" ???
-
I have 2 tables in mydatabase "Account" and "Employee" I want to edit my record but there is a Error messagebox always show ----------------------------- "Recordset is read-only" ----------------------------- How can I fix it? thanks
// I want to Edit password,permission of employee // who have ID="John" >>>>>> Account.ID="John" then..... // Account.Pass="John1" => edit to new password => Account.Pass="John2" // Employee.Permission=2 => edit to new permission => Employee.Permission=3 // QLBH2Set.cpp : implementation of the CAccountSet class // IMPLEMENT_DYNAMIC(CAccountSet, CRecordset) CAccountSet::CAccountSet(CDatabase* pdb) : CRecordset(pdb) { m_ID = _T(""); m_Pass = _T(""); m_Employee_ID = _T(""); m_Permission = 0; m_nFields = 4; m_nDefaultType = dynaset;//snapshot; } CString CAccountSet::GetDefaultConnect() { return _T("ODBC;DRIVER=Microsoft Access Driver (*.mdb);DBQ=C:\\MyDB.mdb"); } CString CAccountSet::GetDefaultSQL() { return _T([Account],[Employee]); } void CAccountSet::DoFieldExchange(CFieldExchange* pFX) { pFX->SetFieldType(CFieldExchange::outputColumn); RFX_Text(pFX, _T("[ID]"), m_ID); RFX_Text(pFX, _T("[Pass]"), m_Pass); RFX_Long(pFX, _T("[Permission]"), m_Permission); RFX_Text(pFX, _T("[Employee_ID]"), m_Employee_ID); } ///////////////////////////////////////////////////////////////////////////// // CChangePassword dialog class CChangePassword : public CDialog { // Construction public: CChangePassword(CWnd* pParent = NULL); // standard constructor CAccountSet m_Set; ..... } ///////////////////////////////////////////////////////////////////////////// // CChangePassword message handlers void CChangePassword::OnOK() { ....... m_Set.m_strFilter = "Account.ID = Employee.Employee_ID"; m_Set.Open(CRecordset::dynaset, _T( "SELECT ALL Account.ID,Account.Pass,Employee.Permission FROM Account INNER JOIN Employee ON Account.ID=Employee.Empoyee_ID" ), CRecordset::executeDirect); // I want to Edit password,permission of employee // who have ID="John" >>>>>> Account.ID="John" // Account.Pass="John1" => edit to new password => Account.Pass="John2" // Employee.Permission=2 => edit to new permission => Employee.Permission=3 m_Set.Edit(); m_Set.m_Pass = strNewPass; m_Set.Update( ); m_Set.Requery (); m_Set.Close(); ..... }