方法大致如下:
//查询数据相等行和列的方法
public static List<string> FindData(DataTable dtTable, string strValue)
{
List<string> list = new List<string>();
string strInfo = string.Empty;
String value;
bool compareRes = true; //比较是否相同
int count = dtTable.Rows.Count;
for (int i = 0; i < count; i++)
{
for (int j = 0; j < dtTable.Columns.Count; j++)
{
//循环比较列的值是否相等
value = dtTable.Rows[i][j].ToString().Trim(); //值
if (strValue.Equals(value)) //相等
{
compareRes = true;
}
else
{
compareRes = false;
continue;
}
if (compareRes == true)
{
strInfo = string.Format("数据和表的行:{0},列:{1}的数据相等!", i + 2, j + 1);
list.Add(strInfo);
}
}
}
return list;
}
温馨提示:答案为网友推荐,仅供参考