更新时间:2023-12-01 14:25:58
我有同样的问题,我做的是创建一个包含数据表名称的字符串,然后将它们添加到我的命令构建器。
I had a same problem and that i did was to create a string with the names of the datatable and then adding them to my command builder.
private string GetColumnNames(DataTable dt)
{
string name = String.Empty;
foreach (DataColumn dc in dt.Columns)
{
name += dc.ColumnName + " NVARCHAR(50)"+", ";
}
return name;
}
private void CreateTableFromDataTable(DataTable dt,string tablename,string columns)
{
string createString = "CREATE TABLE "+tablename+" ("+ columns+")"; //YOUR SQL COMMAND TO CREATE A TABLE
SqlCommand create = new SqlCommand(createString, sqlconnection);
sqlconnection.Open();
create.ExecuteNonQuery();
sqlconnection.Close();
}