Re: Find out how many records in a SQL Table
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@gmail.com> schrieb im Newsbeitrag
news:de01d86e-4efb-4f07-8f9c-4769c1e3b31d@q16g2000yqq.googlegroups.com...
On Feb 3, 4:46 pm, "Andreas Warning" <and...@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.