DataTable Select Function.

Peermohamedmydeen
Posted by Peermohamedmydeen under C# category on | Points: 40 | Views : 4586
From this following code snippet we can filter the DataTable using our query and we can sort by our Order By clause.

This method can be used in a common methods class and can be used through out the application.


public static DataTable DataTableSelect(DataTable dt, string strSql, string strOrderBy)
{
DataRow[] drArray;
DataTable dtTemp = dt.Clone();

try
{
drArray = dt.Select(strSql, strOrderBy);
if(drArray.Length >0)
{
dtTemp = drArray.CopyToDataTable();
}
if(drArray != null) drArray = null; //Dispose Array Object
return dtTemp;
}
catch(Exception ex)
{
Console.WriteLine(ex.Message);
}
finally
{
if(dtTemp != null) dtTemp = null; //Dispose DataTable Objects
if(dt != null) dt = null;
}
}



Thanks and Regards
PMM :)

Comments or Responses

Login to post response