110,500
社区成员
发帖
与我相关
我的任务
分享
SqlConnection con =...............
con.Open();
SqlCommand com;
SqlDataReader dr;
string[] tableName = { "table1", "table2", "table3" }; //用于模拟从数据库读取出的所有表
foreach(string t in tableName)
{
com = new SqlCommand("select * from "+t+"where Key='theCondition'", con);
com.CommandTimeout = 20;
dr = com.ExecuteReader();
try
{
if(dr.Read())
{
//finded!
}
else
{
//do not finded!
}
}
catch
{
continue;
}
finally
{
if(com!=null)
{
com.Dispose();
}
if(dr!=null)
{
dr.Dispose();
}
}
}
if(con!=null)
{
con.Close();
}
---------------------------------------\0