Click here to Skip to main content
15,903,203 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,

I have datatable in which have a Column "DueMONTH".

ID Name DueMonth
101 AAAAA January
102 cccc May
103 AAAAA January


I want to sort this DueMonth in monthwise(January, Febuary) in (Asp GridView or Devexpress GridView).
The month column cannot be changed to Datetime in Database.

Is any other possible from Asp.net.

Thanks
Krishna
Posted

1 solution

Simplest is to add a column to your table. You don't need an actual column in the DB, just an extra column in your select or a new item added to your table in code, such as this (VB):
VB
Dim dt As New DataTable
dt.Columns.Add("ID")
dt.Columns.Add("Name")
dt.Columns.Add("DueMonth")
dt.Columns.Add("SortMonth")
Const DayMonth As String = "01 2000"
dt.Rows.Add(New Object() {101, "AAAAA", "January", Date.Parse("January" & DayMonth).Month})
dt.Rows.Add(New Object() {102, "cccc", "May", Date.Parse("May" & DayMonth).Month})
dt.Rows.Add(New Object() {103, "AAAAA", "January", Date.Parse("January" & DayMonth).Month})
Dim dv As New DataView(dt)
dv.Sort = "SortMonth"
MessageBox.Show(dv(2)(2))


How you'd do it in your SELECT statement depends on your DB type. In Oracle, it'd be something like
SQL
select to_char(to_date('January','month'),'mm')

In SQLServer, it's something closer to the code:
SQL
select DATEPART(MM, YourMonth + ' 01 2000')
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900