5
votes

I created a MySQL database in phpMyAdmin, with an auto incrementing primary key ID. Within phpMyAdmin I can insert records via INSERT INTO MyTable VALUES (null,1,2,3) The null position is for ID.

Loading the DB data into a Delphi application (Connection->Table or Query->DataSetProvider->ClientDataSet->DataSource->DBGrid and DBNavigator), how do I insert a record without manually entering an ID value? If I don't enter a number into the ID field I get an error.

1
show the table definition, auto increment means you don't supply a value and primary key should be not null.. - Tony Hopkinson
@crefird Field 'ID' must have a value. - Al C
@TonyHopkinson For field: id: type:int(11), null:no, key:pri, default:null, extra:auto_increment - Al C
Primary kesy can't be null pal, you should not specify any content for it in your query and mysql will automatically increment it by 1 - user1862764
@user1862764 I understand what you are saying; see my last sentence. Leaving the field blank (in the grid)--not specifying any content for it--I get the error. - Al C

1 Answers

10
votes

Set the Required property for the field to false. This has to be done in the Table or Query and in the ClientDataSet. You have to remove the pfInUpdate from the ProviderFlags of the field, too.