Prev: Dll has no DllMain or CWinApp?
Next: Problems with garbage characters in Chinese Win7 under VS2008.
From: Hector Santos on 4 Feb 2010 05:11 Andreas Warning wrote: > here my code. It shows always a result auf 1. > > What do I wrong > > > > // Create a Action Log Object > m_pActLog=new CActionLog(g_bSQLServer); > m_pActLog->SetTableName(_T("[ActionLog]")); > TRY > { > > m_pActLog->Open( CRecordset::dynaset,_T("Select count(*) from > ActionLog")); > > long zz = m_pActLog->GetRecordCount(); > > } > CATCH(CDBException, e) > { > CString error = CString("ERROR: ") + e->m_strError + CString("\nODBC: ") > + e->m_strStateNativeOrigin; > AfxMessageBox(error); > delete m_pActLog; > AfxMessageBox(_T("ActionLog Table not ok Terminated Program")); > exit(0); > } > END_CATCH > "Goran" <goran.pusic(a)gmail.com> schrieb im Newsbeitrag > news:de01d86e-4efb-4f07-8f9c-4769c1e3b31d(a)q16g2000yqq.googlegroups.com... > On Feb 3, 4:46 pm, "Andreas Warning" <and...(a)gmx.net> wrote: >> Hello, >> >> how can I find out how many records are in a SQL Table. >> >> I used MFC Recordsets >> >> Do you have an idea ? > > +1 for "don't use GetRecordCount()". As Hector says, under the hood, > things are not supposed to work that way with all databases (recordset > record count is not known up-front). SELECT COUNT(*) FROM X is better. > > Note, however, that result is purely informational. For example > (depending on your situation), you should not be using said count+1 as > next record key, due to concurrency issues. If all you want is e.g. > "processing X of Y records", then it's OK. > > Goran. > > -- HLS
From: Hector Santos on 4 Feb 2010 05:13 Use GetFieldValue(), not GetRecordCount(). That will return 1 always. Andreas Warning wrote: > here my code. It shows always a result auf 1. > > What do I wrong > > > > // Create a Action Log Object > m_pActLog=new CActionLog(g_bSQLServer); > m_pActLog->SetTableName(_T("[ActionLog]")); > TRY > { > > m_pActLog->Open( CRecordset::dynaset,_T("Select count(*) from > ActionLog")); > > long zz = m_pActLog->GetRecordCount(); > > } > CATCH(CDBException, e) > { > CString error = CString("ERROR: ") + e->m_strError + CString("\nODBC: ") > + e->m_strStateNativeOrigin; > AfxMessageBox(error); > delete m_pActLog; > AfxMessageBox(_T("ActionLog Table not ok Terminated Program")); > exit(0); > } > END_CATCH > "Goran" <goran.pusic(a)gmail.com> schrieb im Newsbeitrag > news:de01d86e-4efb-4f07-8f9c-4769c1e3b31d(a)q16g2000yqq.googlegroups.com... > On Feb 3, 4:46 pm, "Andreas Warning" <and...(a)gmx.net> wrote: >> Hello, >> >> how can I find out how many records are in a SQL Table. >> >> I used MFC Recordsets >> >> Do you have an idea ? > > +1 for "don't use GetRecordCount()". As Hector says, under the hood, > things are not supposed to work that way with all databases (recordset > record count is not known up-front). SELECT COUNT(*) FROM X is better. > > Note, however, that result is purely informational. For example > (depending on your situation), you should not be using said count+1 as > next record key, due to concurrency issues. If all you want is e.g. > "processing X of Y records", then it's OK. > > Goran. > > -- HLS
From: Andreas Warning on 4 Feb 2010 05:33 When I loops throw the records, than the GetRecordCount works fine. But the loop need 8 secound . here my code: m_pActLog->Open(); while(!m_pActLog->IsEOF()) { m_pActLog->MoveNext(); } long zz = m_pActLog->GetRecordCount(); // zz is 138234 Is there any way to determine faster, how many records are in a recordset ? Thanks Andreas "Andreas Warning" <andy41(a)gmx.net> schrieb im Newsbeitrag news:O5tXVgOpKHA.1548(a)TK2MSFTNGP04.phx.gbl... > Hello, > > how can I find out how many records are in a SQL Table. > > I used MFC Recordsets > > Do you have an idea ? > > Thanks > Andreas >
From: Hector Santos on 4 Feb 2010 06:05 Andreas Warning wrote: > When I loops throw the records, than the GetRecordCount works fine. > > But the loop need 8 secound . > here my code: > > m_pActLog->Open(); > while(!m_pActLog->IsEOF()) > { > m_pActLog->MoveNext(); > } > > long zz = m_pActLog->GetRecordCount(); > > // zz is 138234 > > Is there any way to determine faster, how many records are in a recordset ? > > Thanks > Andreas > > > > > "Andreas Warning" <andy41(a)gmx.net> schrieb im Newsbeitrag > news:O5tXVgOpKHA.1548(a)TK2MSFTNGP04.phx.gbl... >> Hello, >> >> how can I find out how many records are in a SQL Table. >> >> I used MFC Recordsets >> >> Do you have an idea ? >> >> Thanks >> Andreas >> > > -- HLS
From: Cholo Lennon on 4 Feb 2010 08:21 Andreas Warning wrote: > When I loops throw the records, than the GetRecordCount works fine. > > But the loop need 8 secound . > here my code: > > m_pActLog->Open(); > while(!m_pActLog->IsEOF()) > { > m_pActLog->MoveNext(); > } > > long zz = m_pActLog->GetRecordCount(); > > // zz is 138234 > > Is there any way to determine faster, how many records are in a recordset ? > > Thanks > Andreas > In general (it's depend on db provider and recordset configuration) you have to populate the recordset cache before counting, so you should to go to the end prior to any count operation. A better/faster way to do that is: m_pActLog->Open(); m_pActLog->MoveLast(); long zz = m_pActLog->GetRecordCount(); Regards -- Cholo Lennon Bs.As. ARG
First
|
Prev
|
Next
|
Last
Pages: 1 2 3 Prev: Dll has no DllMain or CWinApp? Next: Problems with garbage characters in Chinese Win7 under VS2008. |