Solved

Dataset Column Order Problem

Posted on 2009-04-06
6
277 Views
Last Modified: 2012-05-06
I created a dataset with several TableAdapters built in it.  I have one query that builds a datatable of all users in the system.  I can bind to the gridview without a problem and the results are correct.  However, the order of the columns is not consistant with my query.  For example, Select col1, col2, col3 from table, is displaying in the gridview as col2, col1, col3.
0
Comment
Question by:mmeisel
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
6 Comments
 
LVL 5

Expert Comment

by:P_Ramprathap
ID: 24078205
Use the following

MyDataSet.Tables["MyTable"].Columns["MyColumn"].SetOrdinal(5);  
This puts the Column "MyColumn" to the 6th position in the columns order (0 based index).

Thanks
Ram
0
 
LVL 1

Author Comment

by:mmeisel
ID: 24078306
Can you explain further?  How would I fit that into my code?  My code is below.

       ' Fill Gridview with Users
        Dim usersAdapter As New UsersTableAdapter
        gvUsers.DataSource = usersAdapter.GetUsers()
        gvUsers.DataBind()
0
 
LVL 10

Expert Comment

by:Espavo
ID: 24078698
It seems to me that you need to add "ORDER BY col1, col2, col3" to your dataset query...
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 1

Author Comment

by:mmeisel
ID: 24079599
An ORDER BY shouldn't effect the order in which the columns appear, that's what the SELECT statement is for.  

To elaborate further:
SQL Statement -> SELECT Name, Username, Email, Active, Role FROM Users ORDER BY Name

Displays in the gridview in the following order -> Email, Active, Username, Role, Name.

I'm attempting to use a layered architecture to design the system.  I created a .xsd file for the Data Access Layer.
0
 
LVL 10

Expert Comment

by:Espavo
ID: 24080565
Sorry, I misunderstood what you were saying...
And, you can manually change the order of the GridView columns... (from the template)
0
 
LVL 1

Accepted Solution

by:
mmeisel earned 0 total points
ID: 24108544
Apparently everytime I made a change to a field it put it last.  For instance, original column order: A B C.  I make a change to column B in the query and the new order is now A C B.  I'm using Visual Web Developer 2008.

I was originally databinding my gridview through the Page_Load event.  Now, I created an Object Data Source and binded my gridview to that.  Different approach but it solved my problem in a round about way.
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article discusses the ASP.NET AJAX ModalPopupExtender control. In this article we will show how to use the ModalPopupExtender control, how to display/show/call the ASP.NET AJAX ModalPopupExtender control from javascript, how to show/display/cal…
One of the pain points with developing AJAX, JavaScript, JQuery, and other client-side behaviors is that JavaScript doesn’t allow for cross domain request for pulling content. For example, JavaScript code on www.johnchapman.name could not pull conte…
I've attached the XLSM Excel spreadsheet I used in the video and also text files containing the macros used below. https://filedb.experts-exchange.com/incoming/2017/03_w12/1151775/Permutations.txt https://filedb.experts-exchange.com/incoming/201…
Are you ready to implement Active Directory best practices without reading 300+ pages? You're in luck. In this webinar hosted by Skyport Systems, you gain insight into Microsoft's latest comprehensive guide, with tips on the best and easiest way…

756 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