I am working with DAO in C++ for about three years now. Reading your article I have found that you have learned how to use DAO by trial-error method. I would like to point out some things that you are doing ant that are not needed at all.
First, the part "Adding data ...":
The following two lines are of no use:
database.Execute("INSERT INTO MyTable(Name);");
database.Execute("INSERT INTO MyTable(Age);");
When you have created the table, the columns are already there, not to mention that the two lines don't add Name nor Age into the table, they are syntactic nonsense.
When you are adding new data to the table, there is no need to call MoveNext between the Update and next AddNew.
Next, the getting data from the table:
There is no use of doing
because the GetFieldValue sets the type itself according to the field type (it is like doing something like int i = 1; i = 2;).
I would also recommend using type Integer or SmallInt for storing the Age (and other numeric values), it is easier to work with than with the string values. You can set it in the same way as the VARCHAR:
recordset.SetFieldValue("Age", (long)13) - for Integer
recordset.SetFieldValue("Age", (short)13) - for SmallInt
The short and long get automatically converted to variant.
But getting them is easier:
short age = recordset.GetFieldValue("Age").iVal;
long age = recordset.GetFieldValue("Age").lVal;
(Of course the table field types must be SmallInt resp. Integer for this to work).
I hope my notes will help you and others to understand better the DAO. I was not trying to offend you in any way.
If you need the fastest available access methods for DAO, these are the classes to use.
It is quite possible to achieve > 1100 record inserts per second with considerable other logic / lookups etc. on a P100 (thats how long ago the code was written) using these DAO classes. (these results were consistently achieved in a multithreaded database interface procedure).
The article is a brief introduction - the easiest way to understand these classes is to consider them the same as the standard DAO classes, and expect them to behave the same. IE write your code as you would previously, but simply translate it to use the equivalent functionality - if its there.