Solved

adodataset insert record

Posted on 2004-04-13
7
644 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
Comment Utility

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

   Please clarify...
0
 
LVL 12

Expert Comment

by:Ivanov_G
Comment Utility

   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
Comment Utility
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
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 
LVL 6

Author Comment

by:PHD
Comment Utility
"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
Comment Utility
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
Comment Utility

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
Comment Utility
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

Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
Delphi selector screen 2 57
Magic Software info 18 101
Multiple image collision 13 42
JAudiorecorder record freezing the app 30 28
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…
Objective: - This article will help user in how to convert their numeric value become words. How to use 1. You can copy this code in your Unit as function 2. than you can perform your function by type this code The Code   (CODE) The Im…
In this tutorial you'll learn about bandwidth monitoring with flows and packet sniffing with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're interested in additional methods for monitoring bandwidt…
This tutorial demonstrates a quick way of adding group price to multiple Magento products.

743 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

16 Experts available now in Live!

Get 1:1 Help Now