473,387 Members | 1,619 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

Add a Record at the top of a Dataset

I have an asp webpage on which I have a dropdownlist which I fill from my
database using Datasets. Now I want to add an empty record in the dataset so
the first option of the list is empty but I can only append a record at the
end of the Dataset. Any one has an idea on how I can achieve to append a
record at the top of my dataset.

Thanks
Ivan Sammut

Dec 9 '06 #1
1 1715
Hi Ivan,

If your DataTable has a unique integral column, such as an ID, then sort on
that column when querying the database and bind the list to a DataView that
is also sorted on the ID column. When you add a new row you can set the ID
to one less than the smallest ID value so that it's sorted first by the
DataView:

// table is a DataTable
newRow.ID = (int) table.Compute("MIN(ID)-1");

If you are already sorting the data but not by ID, or if you don't have a
unique integral column on which to sort, then you can add an AutoNumber
column typed as Int32 before you fill the DataTable (assuming that any sort
algorithm has already been performed, such as with an ORDER BY clause in a
database query). Each row will be assigned an incrementing integer starting
from zero. The same code above will apply.

--
Dave Sexton

"Ivan Sammut" <sa*****@hotmail.comwrote in message
news:O6**************@TK2MSFTNGP02.phx.gbl...
>I have an asp webpage on which I have a dropdownlist which I fill from my
database using Datasets. Now I want to add an empty record in the dataset
so the first option of the list is empty but I can only append a record at
the end of the Dataset. Any one has an idea on how I can achieve to append
a record at the top of my dataset.

Thanks
Ivan Sammut


Dec 9 '06 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
by: Tony Stoker | last post by:
I have a .Net web app that adds a record to a SQL database. After the user adds their record I want to have a link that will link them to their new record! The recordID is a AutoNumber in the...
0
by: Patrick | last post by:
I'm working on a contact management application, and need a hand with one aspect... Here's what I want to create: ------------------------------------ A form split into two parts. There is a...
6
by: Alpha | last post by:
I retrieve a table with only 2 columns. One is a auto-generated primary key column and the 2nd is a string. When I add a new row to the dataset to be updated back to the database. What should I...
1
by: Trevor Fairchild | last post by:
Hello all - I've been working in VB6 for about a year and now I've moved "up" to VB.NET. I think I would have fewer problems in learning vb.net if I knew nothing about previous versions of vb......
1
by: Ranny | last post by:
Question: What is the process to Insert a record using Dataset and SQLDataAdapter? Explanation: Thanks to Cor I am able to get a record to load, modify it, and save it to the database. My...
3
by: PAUL | last post by:
Hello, I have 2 datasets I am trying to update. The parent table seems to update fine but when I go update the chiled table I get an error message that says I need a related record in the parent...
1
by: Coty | last post by:
Here's the problem I'm having. I write a record to backend database and upon the postback my record set is not showing the record I just added. If I close the page totally and reopen the page it...
1
by: vbDavidC | last post by:
I am adding a new record to a table via a dataset/adapter. I have got the following to work for me but I am wondering if there is a better way to do this. I am having to have something in my...
9
by: =?Utf-8?B?UHJhdmlu?= | last post by:
We are using .net Framework 1.1 We are having one page on which we are using this Grid component. From this page we open a popup for adding new record as well as for editing an existing record...
0
by: PeterSummer | last post by:
Could someone answer a vb.net database question? what is a good way to code a form so that a user could navigate through a dataset ie: MoveFirst, MoveNext, MovePrevious, MoveLast, Update and...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.