Solved

Dataset Column Order Problem

Posted on 2009-04-06
6
276 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
  • 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
Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

 
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

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

In an ASP.NET application, I faced some technical problems. In this article, I list them out and show the solutions that I found.  I hope it will be useful. Problem: After closing a pop-up window, the parent page should be refreshed automaticall…
Introduction This article shows how to use the open source plupload control to upload multiple images. The images are resized on the client side before uploading and the upload is done in chunks. Background I had to provide a way for user…
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

828 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