Paresh
(Paresh)
October 15, 2018, 12:10pm
1
Hi All,
How to sort data table in ascending order on particular column. There may be a possibility that this column contains a blank value. I don’t want to remove this blank value and neither its position (index).
Can you guys please help me achieving this.
Regards,
Paresh Borole
Divyashreem
(Divyashree Muddagangaiah)
October 15, 2018, 12:27pm
2
if it is in excel Just pass you datatable and column you want to sort ascending or descending.
else you can write inDataTable.Select(your column list)order by column name
1 Like
dkollyns
(Diógenes Kollyns )
October 15, 2018, 12:35pm
3
Hello @Paresh
You can try as @Divyashreem have suggest for you, or as example below:
dt.DefaultView.Sort = “[Column1] ASC, [Column2] ASC”
dt = dt.DefaultView.ToTable
4 Likes
Paresh
(Paresh)
October 15, 2018, 1:27pm
4
Hi @Divyashreem and @dkollyns ,
Thanks for your reply. I am preferring to go with -
dt.DefaultView.Sort = “[Column1] ASC, [Column2] ASC”
dt = dt.DefaultView.ToTable
I want to Pass Column1 As integer in this. How can i get that?
Thanks,
Paresh Borole
1 Like
Divyashreem
(Divyashree Muddagangaiah)
October 15, 2018, 1:30pm
5
dt.DefaultView.Sort = “[Column1] ASC, [Column2] ASC”
dt = dt.DefaultView.ToTable
in this [Column1] is a column name-> Convert.Toint32(iDataTable.Item(“Column1”).ToString) this will convert your column data to int format
2 Likes
Paresh
(Paresh)
October 15, 2018, 1:40pm
6
Hi @Divyashreem ,
Please help me with this syntax error.
Thanks,
Paresh Borole
dkollyns
(Diógenes Kollyns )
October 15, 2018, 2:13pm
8
Hello @Paresh
Try this:
dt2 = dt.clone
dt2.Columns(“Column1”).DataType = Type.GetType(“System.Int32”)
For Each dr As DataRow In dt.Rows
dt2.ImportRow(dr)
Next
dt2.AcceptChanges
dt = dt2.DefaultView.ToTable
2 Likes