由网友([有梦才不怕痛])分享简介:如何使用C#来添加一列的SQL Server表? 例如,我想执行的C#code中的SQL语句:ALTER TABLE [产品]加的[ProductID]整数默认0 NOT NULL解决方案 您应该使用命令:使用(的DbConnection连接=新的SqlConnection(你的连接字符串)){connection....
如何使用C#来添加一列的SQL Server表?
例如,我想执行的C#code中的SQL语句:
ALTER TABLE [产品]加
的[ProductID]整数默认0 NOT NULL
解决方案
您应该使用命令:
使用(的DbConnection连接=新的SqlConnection(你的连接字符串)){
connection.Open();
使用(的DbCommand命令=新的SqlCommand(ALTER TABLE [产品]添加的[ProductID]整数默认0 NOT NULL)){
command.Connection =连接;
command.ExecuteNonQuery();
}
}
How to use C# to add a column for a table of sql server?
For example, I want to execute the following sql in C# code:
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();
}
}
相关推荐
最新文章