?
Solved

Sort

Posted on 2005-03-15
4
Medium Priority
?
187 Views
Last Modified: 2010-04-16
Hi Experts,

I have datatable which is used in Select(filter, sort) etc.
Th problem is that I am trying to sort date column but it treats it as text.
How I can fix that ?

Thank you.
0
Comment
Question by:fpoyavo
[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
  • 2
4 Comments
 
LVL 13

Accepted Solution

by:
dungla earned 2000 total points
ID: 13546405
Your sort column must be in the list of selected field. Here is an example

SqlConnection cn = null;
SqlDataAdapter sdad = null;
try
{
      string strSql = "SELECT * FROM Employees";
      DataSet dstReportData = new DataSet();
      cn = new SqlConnection(CONNECTION_STRING);
      sdad = new SqlDataAdapter(strSql, cn);
      sdad.Fill(dstReportData);

      DataRow[] drowData = dstReportData.Tables[0].Select("EmployeeID <= 6", "BirthDate DESC");
      if (drowData.Length > 0)
      {
            foreach (DataRow drow in drowData)
            {
                  lstData.Items.Add(drow["LastName"].ToString());
            }
      }
}
catch (Exception ex)
{
      MessageBox.Show(ex.Message);
}
0
 
LVL 1

Author Comment

by:fpoyavo
ID: 13546610
Dungla,

Thanks. But I don't see your point here. I have code like this. The problem is that I need to sort column which has DATE in it not just a text.
0
 
LVL 8

Expert Comment

by:gena17
ID: 13547407
Hi,

What is your SQL query for DataTable filling?
Or how do you populate your DataTable?

Gena
0
 
LVL 13

Expert Comment

by:dungla
ID: 13550609
So maybe your Date field is not the DateTime datatype in database. Did you rill your table by data adapter or create by manual?
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

Introduction Although it is an old technology, serial ports are still being used by many hardware manufacturers. If you develop applications in C#, Microsoft .NET framework has SerialPort class to communicate with the serial ports.  I needed to…
Summary: Persistence is the capability of an application to store the state of objects and recover it when necessary. This article compares the two common types of serialization in aspects of data access, readability, and runtime cost. A ready-to…
In this video we outline the Physical Segments view of NetCrunch network monitor. By following this brief how-to video, you will be able to learn how NetCrunch visualizes your network, how granular is the information collected, as well as where to f…
In this video, Percona Solution Engineer Rick Golba discuss how (and why) you implement high availability in a database environment. To discuss how Percona Consulting can help with your design and architecture needs for your database and infrastr…
Suggested Courses

801 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