1 Sql
select top 1 1 from 表 where id = '123' ==>table
if (table == null)
{
“不存在”
}
if (table.rows.count > 0 )
“存在”
else
“不存在”
2 for
///table 需要检索的数据表
///ColName 列名
/// 判断是否存在的值
///return true 存在,false 不存在
private bool IsExists(DataTable table,string ColName,string value)
{
bool bl_exists = false;
if (table == null)
{
return false;
}
for (int i = 0;i < table.Rows.Count;i++)
{
string strName =Convert,toString(table.Rows[i]["ColName"]).Trim();
if (strName == value)
{
bl_exists=true;
}
}
return bl_exists;
}
3Select
private bool IsExists(DataTable table,string ColName,string value)
{
bool bl_exists = false;
if (table == null)
{
return false;
}
DataRow[] dt_temp = table.Select(ColName+"='"+value+"'");
if(dt_temp.Length >0)
{
bl_exists =true;
}
return bl_exists;
}