Hello,
I am evaluating these components with Builder 6.0 and I am trying to add a new record onto a table.
The table Site_ID has these fields.
ID which is a int, the primary flag and is set to auto increment
Name varchar(20)
Notes text
Num int
I was trying to use some of the methods in TMyTable like
Table1->Insert();
Table1->FieldVaues["Name"] = Edit1->Text;
Table1->FieldVaues["Notes"] = Edit2->Text;
Table1->FieldVaues["Num"] = 5;
Table1->Post();
But I seem to get errors when I try it this way.
Am I missing some steps? Or do I need to do it with SQL statements in a TMyQuery component?
Also how do I ensure that ID will be given the next number? I was under the impression MySQL does that automatically?
Thanks in Advance
---Dave
Adding a New Record
> Am I missing some steps?
It looks like correct operators sequence. Please describe the problem more detailed.
> Or do I need to do it with SQL statements in a TMyQuery component?
You can use TMyQuery but this isn't necessary. You should keep in mind that TMyQuery component provides more functionality than TMyTable.
> Also how do I ensure that ID will be given the next number?
As GEswin said, you can use LastInsertID property. Furthermore, after Post you can also check field value for AUTO_INCREMENT field.
> I was under the impression MySQL does that automatically?
MySQL server automatically generates values for fields defined as AUTO_INCREMENT, but the server also allows to insert values into AUTO_INCREMENT fields manually.
It looks like correct operators sequence. Please describe the problem more detailed.
> Or do I need to do it with SQL statements in a TMyQuery component?
You can use TMyQuery but this isn't necessary. You should keep in mind that TMyQuery component provides more functionality than TMyTable.
> Also how do I ensure that ID will be given the next number?
As GEswin said, you can use LastInsertID property. Furthermore, after Post you can also check field value for AUTO_INCREMENT field.
> I was under the impression MySQL does that automatically?
MySQL server automatically generates values for fields defined as AUTO_INCREMENT, but the server also allows to insert values into AUTO_INCREMENT fields manually.