welcome Netizen

Share Your Knowledge.It is a way to achieve immortality

Friday, July 20, 2012

How to remove empty rows from the datatable

Here I want share some useful code,Normally we have get the scenario to the data form the excel table or output table, while getting  in some table contains empty row,when import all the data to datatable we get some empty rows in when binding the record we donn’t like to bind with empty value.
In that case you can use the below code to remove the empty rows from the datatable.


  Dim dt, dt1 As New DataTable
        Dim dr As DataRow()
        dt.Columns.Add("name", GetType(System.String))
        dt.Columns.Add("stud", GetType(System.String))
        dt.Rows.Add("Rahul", "v1")
        dt.Rows.Add("", "")
        dt.Rows.Add("sairam", "v1")
        dt.Rows.Add("sathish", "v1")
        dt.Rows.Add("vengatesh", "v1")
        dt.Rows.Add("Lokesh", "v1")
        dt.Rows.Add("", "v1")
        dt.Rows.Add("", "")
        ''Here filter the empty rows value
        dr = dt.Select("name<>''")
        ''Here clone the dt columns name with dt1
        dt1 = dt.Clone()
        For Each DRow As DataRow In dr
            ''Finally copy the rows to anther datatable dt1

All the empty rows are filtered and stored into another datatable. This is not  the final solution to remove the empty rows,even if you have any other method or code please share here with your


Post a Comment