CPB Mailing List

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: DataBase Question



At 13:52 10/10/98 EDT, you wrote:
>Question....
>
>How do I Create Records in a Table at run-time and fill the records with
data?
>
>Wantabe programmer
>RS 
>
>

There are a few ways but due to the "strangeness" of Variants this way is
probably the easiest and safest, but not the most elegant. I'm assuming you
want to do it programatically not via using input into a DBGrid. Here is
the code: (assume table is called "Table1" with fields "Field1", "Field2",
etc.)

try {
	Table1->Append();
	Table1->FieldValues["Field1"] = (Variant)Value1;
	Table1->FieldValues["Field2"] = (Variant)Value2;
	... etc. ...
	Table1->FieldValues["Fieldn"] = (Variant)ValueN;
	Table1->Post();
}
catch(...) {
	Table1->Delete();
}

There you go. The value variables can be of any type thanks to the Variant
keyword (within reason ie. (Variant)"hello" will not go into a Field that
is of type integer).

The try-catch block is used in case the Post creates problems with the
index/keys of the table. It deletes the row you just appended and then you
can do whatever you need to to get values that will be accepted.

Hope this helps,
Mark.

_____________________________________________________________
Mark Jaskiewicz
markj@itcat.com.au
"Who is General Failure and why is he reading my hard disk?"
_____________________________________________________________



W Komornicki's Home Page | Main Index | Thread Index