[英]How to use C# to add a column for a table of sql server?
How to use C# to add a column for a table of sql server? 如何使用C#为sql server表添加列?
For example, I want to execute the following sql in C# code: 例如,我想在C#代码中执行以下sql:
alter table [Product] add
[ProductId] int default 0 NOT NULL
You should use a Command: 您应该使用命令:
using (DbConnection connection = new SqlConnection("Your connection string")) {
connection.Open();
using (DbCommand command = new SqlCommand("alter table [Product] add [ProductId] int default 0 NOT NULL")) {
command.Connection = connection;
command.ExecuteNonQuery();
}
}
SqlCommand cmd2 = new SqlCommand();
// create columns for healed
cmd2 = new SqlCommand("ALTER TABLE TotalHeals ADD "+Healee+" INT", openCon);
cmd2.ExecuteNonQuery();
Funny how SqlCommand is different then DBCommand 有趣的是SqlCommand与DBCommand有什么不同
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.