How to reorder dataset columns in Visual Studio designer

Written By Steven Chang  |  Tableadapter  |  2 Comments

I use tableadapters whenever I need to talk to a SQL database.

There will be times when I needed to add/remove a field in my table and whenever you “refresh” the tableadapter, the newly added field tend to become the last column in the column order. For example, I added step_type_id field into my existing table:

Database Diagram in Microsoft SQL Server Management
Database Diagram in Microsoft SQL Server Management
Dataset designer in Visual Studio

As you can see, I inserted a new column where I want it to be in tblTreeStep in MSSQL Server Management, and instead of doing the same in Visual Studio’s dataset designer, I take the lazy man’s approach of updating my tableadapter by going thru “Configure” again (I just don’t like doing duplicate work of adding the same column in my dataset designer, setting the type, nullable properties again).

When you do that, Visual Studio tags on the new columns at the end of your table, thus not reflecting the true column order of your actual database table.

A quick way to fix this would be to delete all columns but your primary key column (in this example, my obj_id column), go through “Configure” again and add back all your columns.

Your dataset tableadpter should take on the same column order as your database table’s.

About the Author

The roles I play: Husband, Dad, Son, Brother, Friend, Programmer, Investor, Trader, Marketer, Student, Teacher, Leader, Follower, Influencer