
Find Value in DataTable all Rows and Columns in C# | Search in DataTable
if you write program for find value in DataTable all rows and columns and get this row this program help you
public static DataTable search_in_all_columns(DataTable dtobj, string searchpram)
{
DataTable dt = new DataTable();
dt = dtobj.Copy();
dt.Rows.Clear();
if (!string.IsNullOrEmpty(searchpram) && !string.IsNullOrEmpty(searchpram.Trim()))
{
searchpram = searchpram.ToUpper().Trim();
if (dtobj != null && dtobj.Rows.Count > 0)
{
for (int r = 0; r < dtobj.Rows.Count; r++)
{
bool goin = false;
for (int c = 0; c < dtobj.Columns.Count; c++)
{
if (goin == false && (dtobj.Rows[r][c].ToString().ToUpper()).Contains(searchpram))
{
dt.Rows.Add(dtobj.Rows[r].ItemArray);
goin = true;
}
}
}
}
}
int dtco = dt.Rows.Count;
int dtobjco = dtobj.Rows.Count;
return dt;
}
If you like this blog so pls share and Write Comments about Your experience,
Thank You.
Comments
Post a Comment