Solved

Dataset Column Order Problem

Posted on 2009-04-06
6
273 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
Comment Utility
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
Comment Utility
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
Comment Utility
It seems to me that you need to add "ORDER BY col1, col2, col3" to your dataset query...
0
Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

 
LVL 1

Author Comment

by:mmeisel
Comment Utility
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
Comment Utility
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
Comment Utility
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

Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

Join & Write a Comment

Suggested Solutions

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…
I recently went through the process of creating a Calendar Control of events with the basis of using a database to keep track of the dates that are selectable, one requirement was to have the selected date pop-up in a simple lightbox.  At first this…
This video discusses moving either the default database or any database to a new volume.
In this tutorial you'll learn about bandwidth monitoring with flows and packet sniffing with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're interested in additional methods for monitoring bandwidt…

762 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

11 Experts available now in Live!

Get 1:1 Help Now