473,666 Members | 2,517 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

How to resort dataset table after add new row

I have a table in a dataset whose fields are bound to various controls on my
form. The records are sorted by primary key so when I use the
currencymanager to navigate the data, it all appears sorted. When I add a
new row to this table and save it (using dataadapter.upd ate) it appears at
the end of the list no matter where it should fall in the sorted list. When
I exit and re-enter the form the newly added record is then presented in the
proper sorted order. Clearly when re-entering the form I reload the
dataset, create all the data bindings, etc all from scratch. My question
is that, short of reloading the entire dataset and recreating the bindings,
what do I need to do to "reorder" the data once I add the new row so that
the new row will appear in the proper place in the list. I've tried a
CurrencyManager .Refresh and sorting the dataset.table by the proper column,
but in each case the Currencymanager seems to get confused and all types of
weirdness happens.
Any suggestions? Thanks...
Dec 12 '05 #1
2 7638
John,
I have a table in a dataset whose fields are bound to various controls on
my form. The records are sorted by primary key so when I use the
currencymanage r to navigate the data, it all appears sorted. When I add a
new row to this table and save it (using dataadapter.upd ate) it appears at
the end of the list no matter where it should fall in the sorted list.
Gladly enough otherwise I would never be able to do this
ds.tables(x).ro ws(count-1) = the last added record
When I exit and re-enter the form the newly added record is then presented
in the proper sorted order. Clearly when re-entering the form I reload
the dataset, create all the data bindings, etc all from scratch. My
question is that, short of reloading the entire dataset and recreating the
bindings, what do I need to do to "reorder" the data once I add the new
row so that the new row will appear in the proper place in the list. I've
tried a CurrencyManager .Refresh and sorting the dataset.table by the
proper column, but in each case the Currencymanager seems to get confused
and all types of weirdness happens.
Any suggestions? Thanks...


Use the dataview or better just the defaultview which is the same inbuild in
every datatable

ds.tables(0).de faultview.sort = "Mycolumn" is enough
whatever.dataso urce = ds.tables(0).de faultview

I hope this helps,

Cor
Dec 12 '05 #2
Hi Cor,

Thanks for the tip. I got it to work (finally!), but let me give you the
full story of what I had to do...
1. had to make all references to the databinding equal to the
ds.tables("myfi lename").defaul tview (previously I just used
ds.tables("myfi lename") )
2. using the defaultview.sor t put my added record in order, BUT it affected
the positioning of my databinding the next time I added a record. That is,
the first time I added a record (when the sort was not in effect) I added
the new row and positioned to the last record (ie: count-1). During the
processing of the added record I did the defaultview.sor t so the added
record was in it's proper order, HOWEVER the next time I added a record
(the key field is blank when adding a new record) the position of the record
was 0 and NOT count-1 (because of the sort). So, I simply moved the
defaultview.sor t statement to the form.load sub and now I always position to
row 0 when entering the data for a newly added record, and everything works
fine.
Thanks again for the help.
John

"Cor Ligthert [MVP]" <no************ @planet.nl> wrote in message
news:Oa******** ********@tk2msf tngp13.phx.gbl. ..
John,
I have a table in a dataset whose fields are bound to various controls on
my form. The records are sorted by primary key so when I use the
currencymanag er to navigate the data, it all appears sorted. When I add
a new row to this table and save it (using dataadapter.upd ate) it appears
at the end of the list no matter where it should fall in the sorted list.


Gladly enough otherwise I would never be able to do this
ds.tables(x).ro ws(count-1) = the last added record
When I exit and re-enter the form the newly added record is then
presented in the proper sorted order. Clearly when re-entering the form
I reload the dataset, create all the data bindings, etc all from scratch.
My question is that, short of reloading the entire dataset and recreating
the bindings, what do I need to do to "reorder" the data once I add the
new row so that the new row will appear in the proper place in the list.
I've tried a CurrencyManager .Refresh and sorting the dataset.table by the
proper column, but in each case the Currencymanager seems to get confused
and all types of weirdness happens.
Any suggestions? Thanks...


Use the dataview or better just the defaultview which is the same inbuild
in every datatable

ds.tables(0).de faultview.sort = "Mycolumn" is enough
whatever.dataso urce = ds.tables(0).de faultview

I hope this helps,

Cor

Dec 12 '05 #3

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

Similar topics

1
1084
by: Justin | last post by:
Is there an easy way to export a dataset table as a text file such as a .net class. If not do you have any suggestions? Thanks, Justin.
1
1843
by: James Jensen | last post by:
I ran into a snippet of code that uses a FOR EACH loop to step through the rows in a Dataset.Table object. I understand that the FOR EACH statement implements the MoveNext function of the IEnumerator interface of the InternalDataCollectionBase object. I was wondering if anyone knew whether or not the iterator in this case uses a certain hashing algorithm? The table object in question is filled via a stored procedure that returns its...
1
251
by: jaawaad | last post by:
Does anyone know how i can compute values from dataset table before assigning datagrid source to it??? My data table looks something like this. DATE CAT STEP VALUE 01/16/2006 AAA1 50 1 01/16/2006 AAA1 50 1 01/16/2006 AAA1 50 1 01/16/2006 AAA1 50 1 01/16/2006 AAA1 100 2
2
2726
by: forforumsid | last post by:
Hi all I have a Dataset name: dsMain I popullate with all the data from the database on form load event I have a requirement to filter data as per users requirement on a button click event What I want is that when the user clicks the button the program should query the Dataset table and not the database table and return the result
0
1298
by: =?Utf-8?B?UHVjY2E=?= | last post by:
Hi, I'm using vs2005 and .net 2.0. I have used 2 DirectorySearchers to retrieve Active Directory data and put them into 2 separate dataset tables. I want to create a 3rd dataset table by using the equivalent of SQL join operation. This 3rd table will then be passed into Crystal Report. 1. Sometimes each table could contain 100,000 records or more. Is this the most efficeint way to do this? 2. Since there is no join query for dataset...
2
1751
by: =?Utf-8?B?UHVjY2E=?= | last post by:
Hi, I'm using vs2005 and .net 2.0 I used 2 DirectorySearchers to retrieve data from Active Directory and placed them in 2 dataset tables. I need to perform the SQL equuvakebt of join operation to create a 3rd dataset table that I will then pass to Crystal Report. 1. Sometimes there could be 100,000 records or more per table. Is this the most time efficient way to do it? 2. I tried using the datarelation and looping through each...
3
1872
by: =?Utf-8?B?UHVjY2E=?= | last post by:
Are there any good built-in or availble functions that I can call to sort my dataset datatalbe based on 1 or more of the table's columns? -- Thanks.
9
1643
by: =?Utf-8?B?Sm9obiBSZWV2ZQ==?= | last post by:
How to put a list of rows from dataset table into an array ? I tried with this code but it doesn't help. ArrayList arrayList = new ArrayList(); foreach (DataRow dr in db.dataSetUsers.Tables.Rows) { arrayList.Add (dr); }
0
1172
by: Nick L | last post by:
Here is the PowerShell script I've been working on (.NET question is at the bottom): ### setup SQL connection $conn = new-object System.Data.SqlClient.SqlConnection $conn.ConnectionString = "server=*****;database=****;UID=*****;PWD=*****" ### setup SQL command $cmd = new-object System.Data.SqlClient.SqlCommand ### Get SQL commands from text file
0
8454
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8362
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8878
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8785
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8560
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
1
6200
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
4200
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4372
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
1778
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.