Solved

adodataset insert record

Posted on 2004-04-13
7
672 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Industry Leaders: 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!

 
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

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

The uses clause is one of those things that just tends to grow and grow. Most of the time this is in the main form, as it's from this form that all others are called. If you have a big application (including many forms), the uses clause in the in…
This article explains how to create forms/units independent of other forms/units object names in a delphi project. Have you ever created a form for user input in a Delphi project and then had the need to have that same form in a other Delphi proj…
There are cases when e.g. an IT administrator wants to have full access and view into selected mailboxes on Exchange server, directly from his own email account in Outlook or Outlook Web Access. This proves useful when for example administrator want…
Monitoring a network: why having a policy is the best policy? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the enormous benefits of having a policy-based approach when monitoring medium and large networks. Software utilized in this v…
Suggested Courses
Course of the Month5 days, 21 hours left to enroll

626 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