*** Retriving Rows of Data from Access Tables **
-
Hi Everyone, I’m using Visual C++6, and I have this question regarding Database programming with Microsoft Access. How do I get a certain row’s field names and it’s values?? For example, let’s say I have an Access table such as: CustID CustName Item Price 1 John Pen 1.99 2 Mike Mirror 5.00 3 Erin Pencils 1.00 4 Joe Eraser 1.50 5 Tim CD 14.99 How do retrieve the data of certain rows such as row 2 and row 5?? I would like then to take the values of the selected rows and write it into a new table somewhere else. Is there a simple method such as (SELECT this row and INSERT INTO a database)?? If anyone has any idea, PLEASE LET ME KNOW. Thanks in Advance. Steve P.S. How do I only retrieve the FIELD NAMES of a table?
-
Hi Everyone, I’m using Visual C++6, and I have this question regarding Database programming with Microsoft Access. How do I get a certain row’s field names and it’s values?? For example, let’s say I have an Access table such as: CustID CustName Item Price 1 John Pen 1.99 2 Mike Mirror 5.00 3 Erin Pencils 1.00 4 Joe Eraser 1.50 5 Tim CD 14.99 How do retrieve the data of certain rows such as row 2 and row 5?? I would like then to take the values of the selected rows and write it into a new table somewhere else. Is there a simple method such as (SELECT this row and INSERT INTO a database)?? If anyone has any idea, PLEASE LET ME KNOW. Thanks in Advance. Steve P.S. How do I only retrieve the FIELD NAMES of a table?
databases have tables of tables to keep track of what the user databases are all about ... thats how they pull out the right datatypes and values etc etc ... its called metadata and its stored in the system tables ... if you enable the showing of system tables you can query the db for info on the other tables and select whatever you want all well and good but slower than keeping your own table of tables containing just what you need to know ... which is what i do to get stuff like configurable columns in an abitrary data view, etc etc :)
-
Hi Everyone, I’m using Visual C++6, and I have this question regarding Database programming with Microsoft Access. How do I get a certain row’s field names and it’s values?? For example, let’s say I have an Access table such as: CustID CustName Item Price 1 John Pen 1.99 2 Mike Mirror 5.00 3 Erin Pencils 1.00 4 Joe Eraser 1.50 5 Tim CD 14.99 How do retrieve the data of certain rows such as row 2 and row 5?? I would like then to take the values of the selected rows and write it into a new table somewhere else. Is there a simple method such as (SELECT this row and INSERT INTO a database)?? If anyone has any idea, PLEASE LET ME KNOW. Thanks in Advance. Steve P.S. How do I only retrieve the FIELD NAMES of a table?
G'day Steve, Check out CDaoTableDef and CDaoFieldInfo. Here's a (very) rough example...
CDaoDatabase db; db.Open("DatabaseFileName.mdb", ...other parms...); CDaoTableDef td(&db); td.Open("MyTable"); for(int i = 0; i < td.GetFieldCount(); i++){ CDaoFieldInfo fi; td.GetFieldInfo(i, &fi); // The field's name will be in fi.m_strName; TRACE(_T("Field[%d]: %s\n"), i, fi.m_strName); } td.Close(); db.Close();
Hope this helps, Steve -
G'day Steve, Check out CDaoTableDef and CDaoFieldInfo. Here's a (very) rough example...
CDaoDatabase db; db.Open("DatabaseFileName.mdb", ...other parms...); CDaoTableDef td(&db); td.Open("MyTable"); for(int i = 0; i < td.GetFieldCount(); i++){ CDaoFieldInfo fi; td.GetFieldInfo(i, &fi); // The field's name will be in fi.m_strName; TRACE(_T("Field[%d]: %s\n"), i, fi.m_strName); } td.Close(); db.Close();
Hope this helps, SteveI guess I should have mentioned my exmple (above) is for fetching the field/column names from an existing table in a MS Access database. Steve