Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 689
  • Last Modified:

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 ?











0
PHD
Asked:
PHD
  • 2
  • 2
  • 2
  • +1
2 Solutions
 
Ivanov_GCommented:

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

   Please clarify...
0
 
Ivanov_GCommented:

   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;
0
 
mokuleCommented:
You can't insert record in a given position.

You can only use clause ORDER BY to have records sorted in a desired order
0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
PHDAuthor Commented:
"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.
0
 
esoftbgCommented:
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.

0
 
PHDAuthor Commented:

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.




 
0
 
esoftbgCommented:
as mokule wrote above:
You can't insert record in a given position.
You can only use clause ORDER BY to have records sorted in a desired order.
Don't worry about the physical order of the records in the table: You can have needed order for example:

'SELECT ID, NAME, COUNTRY, STATE, TOWN, ADDRESS FROM CUSTOMERS ORDER BY NAME'
or
'SELECT ID, NAME, COUNTRY, STATE, TOWN, ADDRESS FROM CUSTOMERS ORDER BY COUNTRY, NAME'

I didn't understand your question first time....
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

  • 2
  • 2
  • 2
  • +1
Tackle projects and never again get stuck behind a technical roadblock.
Join Now