Solved

Dataset Column Order Problem

Posted on 2009-04-06
6
274 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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Lots of people ask this question on how to extend the “MembershipProvider” to make use of custom authentication like using existing database or make use of some other way of authentication. Many blogs show you how to extend the membership provider c…
In this Article, I will provide a few tips in problem and solution manner. Opening an ASPX page in Visual studio 2003 is very slow. To make it fast, please do follow below steps:   Open the Solution/Project. Right click the ASPX file to b…
Migrating to Microsoft Office 365 is becoming increasingly popular for organizations both large and small. If you have made the leap to Microsoft’s cloud platform, you know that you will need to create a corporate email signature for your Office 365…
Internet Business Fax to Email Made Easy - With  eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, f…

863 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

Need Help in Real-Time?

Connect with top rated Experts

23 Experts available now in Live!

Get 1:1 Help Now