ODBC and CRecordSet::Update
-
Hi When i use the function CRecordSet::Update, i have an exception. Besides, when i use the function Crecordset::MoveFirst, I don't read the first record. Anyone can help me please. I send you my code. Thanks try { /* APP->m_TmSet -> Open ();*/ CTmSet tmset; if (tmset.IsOpen () ) tmset.Close () ; tmset.Open(); MessageBox(NULL,"passe","passe3",MB_OK); //if ( APP->m_TmSet -> CanAppend () ) if (tmset.CanAppend () ) { MessageBox(NULL,"avant new","passe",MB_OK); //tmset.AddNew(); tmset.MoveFirst(); tmset.Requery () ; //tmset.Edit(); for (int n=0;n<20;n++) { char buf[10]; MessageBox(NULL,tmset.m_TM_NAME,"nom",MB_OK); wsprintf(buf,"%ld",tmset.m_TM_ID); MessageBox(NULL,buf,"id",MB_OK); tmset.MoveNext(); } int a=tmset.GetRecordCount(); wsprintf(buf,"%ld",a); MessageBox(NULL,buf,"nb record",MB_OK); /*tmset.m_BAY_CODE =TmSql->numBay ; tmset.m_TM_ID =TmSql->numTm ; tmset. m_TM_NAME=TmSql->libTm ; tmset.m_TM_UNIT =TmSql->libUnit; tmset.m_TM_ARCHIVE =TmSql->FlgArchive ; tmset.m_TM_STATE_CURRENT =0; tmset.m_TM_DATE_CURRENT =0 ; tmset.m_TM_DATE_OK_CURRENT=0 ;*/ tmset.m_BAY_CODE =0 ; tmset.m_TM_ID =0 ; tmset. m_TM_NAME="a" ; tmset.m_TM_UNIT ="b"; tmset.m_TM_ARCHIVE =0 ; tmset.m_TM_STATE_CURRENT =0; tmset.m_TM_DATE_CURRENT =0 ; tmset.m_TM_DATE_OK_CURRENT=0 ; if (tmset.CanUpdate () !=0) { MessageBox(NULL,"avant Update ","passe",MB_OK); tmset.Update(); MessageBox(NULL,"après Update","passe",MB_OK); } if ( tmset.IsEOF ()!=0 ) tmset.MoveLast (); tmset.Requery () ; tmset.MoveLast () ; MessageBox(NULL,"ajoute3","passe",MB_OK); // UpdateData ( FALSE ) ; } else AfxMessageBox ( "Can Not Append a Record" ) ; } catch( CDBException* e ) { AfxMessageBox( e->m_nRetCode, MB_ICONEXCLAMATION ); // Delete the incomplete recordset object /* delete m_pSet; m_pSet = NULL;*/ e->Delete(); }
-
Hi When i use the function CRecordSet::Update, i have an exception. Besides, when i use the function Crecordset::MoveFirst, I don't read the first record. Anyone can help me please. I send you my code. Thanks try { /* APP->m_TmSet -> Open ();*/ CTmSet tmset; if (tmset.IsOpen () ) tmset.Close () ; tmset.Open(); MessageBox(NULL,"passe","passe3",MB_OK); //if ( APP->m_TmSet -> CanAppend () ) if (tmset.CanAppend () ) { MessageBox(NULL,"avant new","passe",MB_OK); //tmset.AddNew(); tmset.MoveFirst(); tmset.Requery () ; //tmset.Edit(); for (int n=0;n<20;n++) { char buf[10]; MessageBox(NULL,tmset.m_TM_NAME,"nom",MB_OK); wsprintf(buf,"%ld",tmset.m_TM_ID); MessageBox(NULL,buf,"id",MB_OK); tmset.MoveNext(); } int a=tmset.GetRecordCount(); wsprintf(buf,"%ld",a); MessageBox(NULL,buf,"nb record",MB_OK); /*tmset.m_BAY_CODE =TmSql->numBay ; tmset.m_TM_ID =TmSql->numTm ; tmset. m_TM_NAME=TmSql->libTm ; tmset.m_TM_UNIT =TmSql->libUnit; tmset.m_TM_ARCHIVE =TmSql->FlgArchive ; tmset.m_TM_STATE_CURRENT =0; tmset.m_TM_DATE_CURRENT =0 ; tmset.m_TM_DATE_OK_CURRENT=0 ;*/ tmset.m_BAY_CODE =0 ; tmset.m_TM_ID =0 ; tmset. m_TM_NAME="a" ; tmset.m_TM_UNIT ="b"; tmset.m_TM_ARCHIVE =0 ; tmset.m_TM_STATE_CURRENT =0; tmset.m_TM_DATE_CURRENT =0 ; tmset.m_TM_DATE_OK_CURRENT=0 ; if (tmset.CanUpdate () !=0) { MessageBox(NULL,"avant Update ","passe",MB_OK); tmset.Update(); MessageBox(NULL,"après Update","passe",MB_OK); } if ( tmset.IsEOF ()!=0 ) tmset.MoveLast (); tmset.Requery () ; tmset.MoveLast () ; MessageBox(NULL,"ajoute3","passe",MB_OK); // UpdateData ( FALSE ) ; } else AfxMessageBox ( "Can Not Append a Record" ) ; } catch( CDBException* e ) { AfxMessageBox( e->m_nRetCode, MB_ICONEXCLAMATION ); // Delete the incomplete recordset object /* delete m_pSet; m_pSet = NULL;*/ e->Delete(); }
You need to call AddNew or Edit Methods before you call Update. Your code currently has them commented out.