C#判断DataTable某字段是否包含某值
程序员文章站
2022-06-10 18:08:06
...
// <summary>
/// 判断DataTale中判断某个字段中包含某个数据
/// </summary>
/// <param name="dt"></param>
/// <param name="columnName"></param>
/// <param name="fieldData"></param>
/// <returns></returns>
public static Boolean IsIncludeData(DataTable dt, String columnName, string fieldData)
{
if(dt==null)
{
return false;
}
else
{
if (dt.Select(columnName+"='"+fieldData+"'").Length>0)
{
return true;
}
else
{
return false;
}
}
}
2、过滤筛选条件
DataTable dt = new DataTable();
DataView dataview = new DataView(dt);
dataview.RowFilter = "Name like'%" + txtName + "%'";