我想用c#删除sql数据库中的表 [英] I want to delete a table in sql database with c#
本文介绍了我想用c#删除sql数据库中的表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
嗨
表名比较
数据库名称Proge144
我要删除带有c#的sql数据库中的表。
(比较表中没有数据)
请帮帮我
Hi
table name Comparess
database name Proge144
I want to delete a table in sql database with c#.
(Not Data in Comparess table)
please Help me
推荐答案
您可以使用ADO.NET并执行DROP TABLE SQL命令。
You can use ADO.NET and just execute the DROP TABLE SQL command.
using (SqlConnection connection = new SqlConnection(
connectionString))
{
SqlCommand command = new SqlCommand("DROP TABLE Comparess", connection);
command.Connection.Open();
command.ExecuteNonQuery();
command.Connection.Close();
}
删除表并检查语句是否成功 -
Drop a table and check if the statement succeeded -
con.open();
string str=" Drop table compass";
cmd= new SqlCommand(str,con);
int r=cmd.executenonquery();
if(r<0)
{
//Dropped successfully
}
else
{
//There was an error
}
这篇关于我想用c#删除sql数据库中的表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文