[英]How do I copy whole tables from ODBC source to SQL server using c# .Net without specifying columns
This will be in C#这将在 C# 中
I would like to do this without specifying column names as will be multiple tables.我想在不指定列名的情况下执行此操作,因为这将是多个表。
Will be a nightly scheduled task, truncating old then writing new.将是每晚计划的任务,截断旧的然后写新的。
I have a working odbc connection and sql connection.我有一个可用的 odbc 连接和 sql 连接。
One thought is to use dapper but cast to an object instead of a model class.一种想法是使用 dapper 但转换为对象而不是模型类。 Would this work.
这行得通吗?
After populating a datatable via odbc, you can write to sql db with通过 odbc 填充数据表后,您可以写入 sql db
using (var bulkCopy = new SqlBulkCopy(sqlConnection))
{
bulkCopy.DestinationTableName = dataTable.TableName;
bulkCopy.WriteToServer(dataTable);
}
No need to specify column names无需指定列名
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.