Link to home
Start Free TrialLog in
Avatar of PHD
PHD

asked on

adodataset insert record


Hello,

I use a database MS SQL.

I try to insert records between two others and get the result in a dbgrid.

First I select a row in the dbgrid.

By pressing a button, the program execute : tadodataset(wwDBGrid1.DataSource.DataSet).Insert;

My form contains tdbedit controls bound to the dataset via a datasource. I enter values in each dbedit controls.

then by pressing another button, it execute : tadodataset(wwDBGrid1.DataSource.DataSet).Post;

When I execute this code, the record is added at the end of the dataset as an append statement.

How can I do without have to add another database field ?











Avatar of Ivanov_G
Ivanov_G
Flag of Bulgaria image


   "How can I do without have to add another database field ?"

   Please clarify...

   If you mean without the DBEdits ...

   wwDBGrid1.DataSource.DataSet.Insert;
   wwDBGrid1.DataSource.DataSet.FieldByName('Field1').AsInteger := 1;
   wwDBGrid1.DataSource.DataSet.FieldByName('Field2').AsString := 'Test';
   wwDBGrid1.DataSource.DataSet.Post;
ASKER CERTIFIED SOLUTION
Avatar of mokule
mokule
Flag of Poland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of PHD
PHD

ASKER

"How can I do without have to add another database field ?"

   Please clarify...


I mean without a field in my table specifying the order of the record and then make an order by clause.
By pressing a button, the program will execute : tadodataset(wwDBGrid1.DataSource.DataSet).Edit;
You change values in some or all dbedit controls.
then by pressing another button, it execute : tadodataset(wwDBGrid1.DataSource.DataSet).Post;
When you execute this code, the record will update the current record of the dataset.
This will not append a new record.

Avatar of PHD

ASKER


I think, Ihave the solution based on the comment of 'esoftbg'.

I make an edit at current position with the new record to insert and then I set the ID of all next records +1

My table should be ordered as expected

Thanks for all, I try this.




 
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial