Solved

adodataset insert record

Posted on 2004-04-13
7
647 Views
Last Modified: 2010-04-05

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
Comment
Question by:PHD
  • 2
  • 2
  • 2
  • +1
7 Comments
 
LVL 12

Expert Comment

by:Ivanov_G
ID: 10813437

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

   Please clarify...
0
 
LVL 12

Expert Comment

by:Ivanov_G
ID: 10813465

   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
 
LVL 17

Accepted Solution

by:
mokule earned 425 total points
ID: 10813469
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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
LVL 6

Author Comment

by:PHD
ID: 10813556
"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
 
LVL 12

Expert Comment

by:esoftbg
ID: 10813595
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
 
LVL 6

Author Comment

by:PHD
ID: 10813637

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
 
LVL 12

Assisted Solution

by:esoftbg
esoftbg earned 75 total points
ID: 10816473
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

A lot of questions regard threads in Delphi.   One of the more specific questions is how to show progress of the thread.   Updating a progressbar from inside a thread is a mistake. A solution to this would be to send a synchronized message to the…
Have you ever had your Delphi form/application just hanging while waiting for data to load? This is the article to read if you want to learn some things about adding threads for data loading in the background. First, I'll setup a general applica…
This Micro Tutorial hows how you can integrate  Mac OSX to a Windows Active Directory Domain. Apple has made it easy to allow users to bind their macs to a windows domain with relative ease. The following video show how to bind OSX Mavericks to …
Along with being a a promotional video for my three-day Annielytics Dashboard Seminor, this Micro Tutorial is an intro to Google Analytics API data.

910 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now