Rearranging Dataset after updating Database

Govind Sankar

Active member
Joined
May 15, 2020
Messages
27
Programming Experience
Beginner
Hi,

I have a database and a dataset in visual studio. I updated the database by adding two new columns to a table in the database. Then I updated the dataset using Configure Data Source With Wizard and everything is fine. But the problem is the order of the columns in the dataset. In the database I added the two new columns in the middle of the table but in the dataset it is showing at the end. I want those two new columns also in the middle of the dataset like in the database. I searched online and the answer I got was to delete all the columns and configure the dataset again. I am scared to do that. So is there any other way to rearrange the dataset. Thank You.
 

Skydiver

Staff member
Joined
Apr 6, 2019
Messages
1,575
Location
Virginia Beach, VA
Programming Experience
10+
First of all use source control. That way you can always be able to go back to a previous version if things don't pan out.

Next: I believe that the data set definition files used by Visual Studio is just XML. You'll have to break out notepad or your favorite text editor and rearrange the columns in the XML. There may also be a display order attribute in the XML that you can twiddle. I don't recall. I have abandoned typed DataSets a long time ago because it's a great software architect's tool when prototyping, but sucks for the front line developer who has to maintain the code long after the architect has moved on to other things.

Third, you could opt to just re-arrange the columns in the UI. Of course, it will be a pain in the butt if you used autogenerate columns everywhere, but it will be doable. Just twiddle the DisplayIndex properties of the appropriate columns.
 

jmcilhinney

C# Forum Moderator
Staff member
Joined
Apr 23, 2011
Messages
3,049
Location
Sydney, Australia
Programming Experience
10+
Just delete the table from the DataSet altogether and then run the configuration wizard to add it back again. The table will be added anew with the same schema as the database.

EDIT: Just realised that you already mentioned that. I've done it plenty of times so it's really no big deal. That said, there's always the possibility that things can go wrong. I agree about using source control but, even without that. You can backup a solution locally simply by making a copy of the entire solution folder. If you break something, delete the working copy and replace with your backup.
 
Top Bottom