need help!!!!
-
Hi all the guru, I am currently using ODBC to access MS SQL. Can anybody tell me how to get number of columns if given table name? Thanks thanks thanks!!!:eek: vivi
Try Desc "tablename" query. Get the recordcount from the recordset. The count you get is the column count.
-
Hi all the guru, I am currently using ODBC to access MS SQL. Can anybody tell me how to get number of columns if given table name? Thanks thanks thanks!!!:eek: vivi
If you have MSDN I would also suggest searching for the file "catsets.h". This is a bunch of CRecordset-derived classes that allow you to use a table name to get the names, types, and everything else you want to know about the columns. There's also ones to list all the tables, stored procedures,queries, views, primary keys, foreign keys, etc. Hope this helps!! If it's broken, I probably did it bdiamond
-
Try Desc "tablename" query. Get the recordcount from the recordset. The count you get is the column count.
Vikram, You need to be careful if you are suggesting to use CRecordset's GetRecordCount() function. According to MSDN, this function only returns the number of seen records in the set. So, right after opening the set, the function will return only 1. You would want to execute another SQL query that counts the records in the resulting set using the COUNT aggregate, or (more inefficiently) loop through the recordset with CRecordset, and then call GetRecordCount(). If your suggestion did not depend upon CRecordset, this, of course, doesn't matter. Sincerely, Alexander Wiseman Est melior esse quam videri It is better to be than to seem
-
Vikram, You need to be careful if you are suggesting to use CRecordset's GetRecordCount() function. According to MSDN, this function only returns the number of seen records in the set. So, right after opening the set, the function will return only 1. You would want to execute another SQL query that counts the records in the resulting set using the COUNT aggregate, or (more inefficiently) loop through the recordset with CRecordset, and then call GetRecordCount(). If your suggestion did not depend upon CRecordset, this, of course, doesn't matter. Sincerely, Alexander Wiseman Est melior esse quam videri It is better to be than to seem
-
I was also told the same thing that you just said, but was told to use MoveLast, then MoveFirst, and the count should be right. ;) If it's broken, I probably did it bdiamond
Hmm, that's interesting. I've never tried that, but MSDN says this: [MSDN] Caution The record count is maintained as a "high water mark," the highest-numbered record yet seen as the user moves through the records. The total number of records is only known after the user has moved beyond the last record. For performance reasons, the count is not updated when you call MoveLast. To count the records yourself, call MoveNext repeatedly until IsEOF returns nonzero. Adding a record via CRecordset:AddNew and Update increases the count; deleting a record via CRecordset::Delete decreases the count. [/MSDN] It might work, though that paragraph seems to mention it specifically. Sincerely, Alexander Wiseman Est melior esse quam videri It is better to be than to seem
-
Hmm, that's interesting. I've never tried that, but MSDN says this: [MSDN] Caution The record count is maintained as a "high water mark," the highest-numbered record yet seen as the user moves through the records. The total number of records is only known after the user has moved beyond the last record. For performance reasons, the count is not updated when you call MoveLast. To count the records yourself, call MoveNext repeatedly until IsEOF returns nonzero. Adding a record via CRecordset:AddNew and Update increases the count; deleting a record via CRecordset::Delete decreases the count. [/MSDN] It might work, though that paragraph seems to mention it specifically. Sincerely, Alexander Wiseman Est melior esse quam videri It is better to be than to seem