查询数据库中是否有某数据表存在的一种处理方式

今天做小项目的时候,遇到这么一个问题

 

于是思路就是说,用count(*) 来查询数据库中是否有这个表,我用到如下代码

 

 

ContractedBlock.gif ExpandedBlockStart.gif 代码
 
   
private void button6_Click(object sender, EventArgs e)
{
SqlConnection sqlCon1
= new SqlConnection("Data Source = BTAP - SHOW;Initial Catalog = myluoyi;Integrated Security = True");
sqlCon1.
Open ();
SqlCommand cmdtext
= new SqlCommand(" select count ( * ) from information_schema.tables where TABLE_NAME = ' T_union" + str +" ' ", sqlCon1);
int Value = ( int )cmdtext.ExecuteScalar();
// label1. Text = "有" + Value.ToString() + "条记录";
sqlCon1.
Close ();

if (Value == 0 )
{
if (MessageBox.Show("数据还未处理过,是否现在处理?", "确认", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
{
SqlCommand cmd1
= new SqlCommand(" select distinct A.LinkID,A.Speed,B.Length,A. Len ,A.Time,A.sampleNum,B.Class into T_union" + str + " from T_youdutwo B inner join T_yongdu A on A.LinkID = B.LinkID", sqlCon1);
DataTable dt
= new DataTable("T_youduthree123");
SqlDataAdapter dAd
= new SqlDataAdapter(cmd1);
dAd.Fill(dt);
sqlCon1.
Close ();
MessageBox.Show("数据处理完毕!");
button6.Enabled
= false;
button7.Enabled
= true;
button8.Enabled
= true;
button9.Enabled
= true;
}
}
else
{
MessageBox.Show("数据已经处理过了,您可以直接查询对应道路等级信息了!","提示",MessageBoxButtons.OK,MessageBoxIcon.Exclamation);
button6.Enabled
= false;
button7.Enabled
= true;
button8.Enabled
= true;
button9.Enabled
= true;
}


for ( int j = 0 ; j < 2500000 ; j ++ ) { }
if (p.Value != p.Maximum)
{
p.PerformStep();
// 按照 Step 属性中指定的数量增加进度栏的值
int l_value = 100 * (p.Value - p.Minimum) / (p.Maximum - p.Minimum);
}

}

 

 

 

注意问题的关键就在于下面这句:

 

 

 
  
select count ( * ) from information_schema.tables where TABLE_NAME = ‘需要的表名字’

 

 

 

 

 

转载于:https://www.cnblogs.com/52yixin/articles/1817240.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值