如何使用C#Visual Studio在数据库文件中的表中添加列 [英] How I Add Column In Table Which Is In Database File By Using C# Visual Studio

查看:406
本文介绍了如何使用C#Visual Studio在数据库文件中的表中添加列的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

1 - 我希望使用c#visual studio在表中插入列

2-数据库文件中存在的表,由ms sql server

1-i want to insert column in table by using c# visual studio
2- the table exist in database file , which is created by ms sql server

推荐答案

示例代码

Sample code
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();
    }
}


这篇关于如何使用C#Visual Studio在数据库文件中的表中添加列的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆