c# - ORDER BY year and date in mysql and gridview -


im having salary table,in im storing salary details corresponding month , year , payment date.im displaying these data in gridview in asp.net c# application. want display data latest in first page. below sample salary database:

+------------+-------+----------+------+----------+------+-------------+ | employeeid | gross | totalded | net  |  month   | year | paymentdate | +------------+-------+----------+------+----------+------+-------------+ |       2066 |  2219 |     3750 | 1531 | january  | 2016 | 30.01.2016  | |       2023 |  2218 |     1649 |  570 | january  | 2016 | 30.01.2016  | |       2001 |  2219 |     3750 | 1531 | october  | 2015 | 30.10.2015  | |       2023 |  2218 |     1649 |  570 | october  | 2015 | 30.10.2015  | |       2034 |  2328 |     5728 | 3400 | october  | 2015 | 30.10.2015  | |       2023 |  2218 |     1649 |  570 | november | 2015 | 30.11.2015  | |       2030 |  2219 |     1550 |  669 | november | 2015 | 30.11.2015  | |       2047 |  2218 |     1649 |  570 | november | 2015 | 30.11.2015  | |       2031 |  2219 |     8450 | 6231 | december | 2015 | 30.12.2015  | |       2057 |  2219 |     8450 | 6231 | december | 2015 | 30.12.2015  | |       2023 |  2218 |     1649 |  570 | december | 2015 | 30.12.2015  | +------------+-------+----------+------+----------+------+-------------+ 

i want table display in gridview pagination.

 string squery = @"select employeeid,grosssalary,totalded,netsalary,month,year,paymentdate                                      salary ";                  mysqldataadapter ada = new mysqldataadapter(squery, globalcs.objmycon);                                            using (datatable dt = new datatable())                 {                     ada.fill(dt);                     gridview1.datasource = dt;                     gridview1.databind();                 } 

but displays latest last page. if use

select employeeid,grosssalary,totalded,netsalary,month,year,paymentdate salary order paymentdate

then displays jan2016,oct 2016,nov 2016,dec 2016. want display jan2016,dec 2015, nov 2015, oct 2015 tried

select employeeid,grosssalary,totalded,netsalary,month,year,paymentdate  salary order month , year 

the output mixing of data. how can that?

if paymentdate string datatype order paymentdate order results in lexicographical order.

before order convert paymentdate date.

select    `employeeid`,   `grosssalary`,   `totalded`,   `netsalary`,   `month`,   `year`,   `paymentdate`   salary  order str_to_date(`paymentdate`,'%d.%m.%y') desc 

sql fiddle demo

note :- bad practice store date data in string datatype instead of date datatype


Comments

Popular posts from this blog

how to insert data php javascript mysql with multiple array session 2 -

multithreading - Exception in Application constructor -

windows - CertCreateCertificateContext returns CRYPT_E_ASN1_BADTAG / 8009310b -