?
Solved

Dataset Column Order Problem

Posted on 2009-04-06
6
Medium Priority
?
280 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
Independent Software Vendors: 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

New feature and membership benefit!

New feature! Upgrade and increase expert visibility of your issues with Priority Questions.

Question has a verified solution.

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

I have developed many web applications with asp & asp.net and to add and use a dropdownlist was always a very simple task, but with the new asp.net, setting the value is a bit tricky and its not similar to the old traditional method. So in this a…
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…
In this brief tutorial Pawel from AdRem Software explains how you can quickly find out which services are running on your network, or what are the IP addresses of servers responsible for each service. Software used is freeware NetCrunch Tools (https…
Have you created a query with information for a calendar? ... and then, abra-cadabra, the calendar is done?! I am going to show you how to make that happen. Visualize your data!  ... really see it To use the code to create a calendar from a q…

777 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