|
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
|
|
|
|
|
Lauren,
Thanks for the reponse. I've looked up metadata in the MSDN library but it was not listed under C++ codes. Can you provide me with some sample codes??
Thanks
Steve
|
|
|
|
|
i should say that i dont use crecordset or cdatabase objects as i find them a bit clumsy ... maybe i'm just old fashioned
|
|
|
|
|
G'day Steve,
Check out CDaoTableDef and CDaoFieldInfo.
Here's a (very) rough example...
<br />
CDaoDatabase db;<br />
db.Open("DatabaseFileName.mdb", ...other parms...);<br />
<br />
CDaoTableDef td(&db);<br />
td.Open("MyTable");<br />
<br />
for(int i = 0; i < td.GetFieldCount(); i++){<br />
CDaoFieldInfo fi;<br />
td.GetFieldInfo(i, &fi);<br />
<br />
TRACE(_T("Field[%d]: %s\n"), i, fi.m_strName);<br />
}<br />
<br />
td.Close();<br />
db.Close();<br />
Hope this helps,
Steve
|
|
|
|
|
I 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
|
|
|
|
|
Steve,
Thanks for your response and codes.
How can I then retrieve the values of the table by certain rows?
Steve
|
|
|
|
|
G'day Steve,
Have a look at the CDaoRecordset class in the VC++ docs.
Something like the following should work. (I haven't tried this as I use Class Wizard generated recordsets, but I think is hould work OK).
CDaoDatabase db;
db.Open("AccessFileName.mdb", ...);
CDaoTableDef td;
td.Open("MyTable");
CDaoRecordset set(&db);
set.Open(&td);
int nNumRecords = set.GetRecordCount();
set.Move(5);
COleVariant var;
set.GetFieldValue(_T("Name"), var);
set.Move(3);
set.GetFieldValue(_T("Name"), var);
set.Close();
td.Close();
db.Close();
Hope this makes sense.
Steve
|
|
|
|
|
Steve,
Thanks for your input again. But I'm having trouble using the codes.
I'm getting the following error messages:
'CDaoDatabase' : undeclared identifier
same thing goes for CDaoTableDef and CDaoRecordset.
But the thing is that I've already declared the following in my program:
#include afxdao.h
Am I missing something else??
PLEASE LET ME KNOW. Thanks again!
Steve
|
|
|
|
|
Can I assume any of these dlls will always be on a windows system?
Advapi32.dll
Gdi32.dll
Kernel32.dll
Mfc42.dll
Msvcrt.dll
User32.dll
I ran the dependency checker and this is what it listed. However, I thought dlls like kernel32.dll and gdi32.dll should already be on a windows system. How can I check to see what dlls should already be on a system and what dlls I can distribute legally?
|
|
|
|
|
All those except MFC42.DLL and MSVCRT.DLL are part of the OS and will be present. Check the {VSTUDIO DIR}\vc98\redist.txt file for a list of redistributables.
|
|
|
|
|
Anyone know how to use the Tab Control??? I have difficulty of using the tab control!! Any can write a simple Tab Control example for me???
Thanks!!
|
|
|
|
|
How would the following C declaration look like in C++
double (func*)(); /* pointer to a function */
Thanks.
|
|
|
|
|
Sorry, the C declaration should look like this;
double (*func)(); /* pointer to a function */
|
|
|
|
|
Exactly the same.
|
|
|
|
|
I'am Doing a project on Image Processing in VC++?
I Have problems while comparing Image Files?
Also I Have to make the negetive of an image?
Please send your suggetions to me.
|
|
|
|
|
I'am Doing a project on Image Processing?
I Have problems while comparing Image Files?
Also I Have to make the negetive of an image?
Please send your suggetions to me.
|
|
|
|
|
How To Compare Image Files?
|
|
|
|
|
Some programs offer the capability to start when window starts? How to make this effect? Thanks alls!
|
|
|
|
|
Hi,
take a look to this CodeGuru article:
http://codeguru.earthweb.com/misc/OnBoot.shtml
Best regards
Holger
|
|
|
|
|
Some programs offer the capability to start when window starts? How to make this effect? Thanks alls!
|
|
|
|
|
Just add a string value under the registry key "HKEY_LOCAL_MACHINE\Software\Microsoft\Windows\CurrentVersion\run\"
The name of the value can be whatever you want and the string will be the path to your app.
Hope this helps.
|
|
|
|
|
VC 6 (SP4), Win 2000 pro (SP1), IE 5.5
A beta tester has reported a problem on the same environment listed above i.e. the platform the application was compiled on. None other of the 15 testers have this trouble using win95,98,NT,2000.
When this tester tries to access the menus they appear, can be selected but do nothing. Buttons work although menus don't, even though the code behind them for the function and the UPDATE_UI handler is the same, ie they have the same message ID. The UPDATE_UI handler is working, clicking the menu is failing.
After 10 years of Win development I have never seen this, cannot reproduce it, however trust the testers response as we have had a number of communications.
I suspect that a missing or incompatible runtime dll is the cause but so far haven't been able to find it. Those we ship are:
* mfc42.dll
* msvcrt.dll
* msvcrt40.dll
* msvcirt.dll
* msvcp60.dll
If anyone has any suggestions on this, it would be much appreciated.
|
|
|
|
|
1)
I recently try to create a password protection program!!! But the problem was when I press "ENTER" in the edit box it will exit the program!!!! Anyone know how to fix this problem!!!(I want the Password check box checked in the property of edit box)!!
2)
Are there a WM_KEYDOWN event for the edit box control???? What I want to do is when the user press "enter" key in the edit box it will checks to see if the password entered is it correct or not!!!!
Any Help with these 2 problems????
THANKS FOR THE HELPER!~!!!!
|
|
|
|
|
You need to override PreTranslateMessage for your dialog, then when you recieve a WM_KEYDOWN message that is VK_RETURN, check to see if the window handle of the message is equal to the window handle of the edit box, if so handle the message, otherwise pass it on to the base class.
|
|
|
|