Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 193
  • Last Modified:

Sort

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
fpoyavo
Asked:
fpoyavo
  • 2
1 Solution
 
dunglaCommented:
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
 
fpoyavoAuthor Commented:
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
 
gena17Commented:
Hi,

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

Gena
0
 
dunglaCommented:
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

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

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

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now