本文介绍了如何添加sql datatable列?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何动态地将列添加到sql datatable?
列数可能不同。未定义。
How dynamically add columns to sql datatable?
Columns counts may be different.it is not defined.
推荐答案
using (DbConnection connection = new SqlConnection("Your connection string")) {
connection.Open();
using (DbCommand command = new SqlCommand("alter table [YourTableName] add [YourColumnName] int default 0 NOT NULL")) {
command.Connection = connection;
command.ExecuteNonQuery();
}
}
为了更准确地回答,我们需要更多细节,如Maciej Los提到的。
For more precisely answer we need more details like Maciej Los mentioned.
这篇关于如何添加sql datatable列?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!