[英]How to use C# to add a column for a table of sql server?
如何使用C#為sql server表添加列?
例如,我想在C#代碼中執行以下sql:
alter table [Product] add
[ProductId] int default 0 NOT NULL
您應該使用命令:
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();
有趣的是SqlCommand與DBCommand有什么不同
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.