将数据表数据传输到SQLserver [英] Transfer Datatable data into SQLserver
本文介绍了将数据表数据传输到SQLserver的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
亲爱的所有人
我一直在尝试将数据表数据复制到sqlserver现有表中.我尝试了在Web上找到的不同方法,但是这些方法都不适合我的情况:(
这是我使用的最新方法,它收到在System.Data .dll中发生类型为"System.Data.SqlClient.SqlException的未处理的异常""错误.
非常感谢您的帮助
Dear all
I''ve been trying to copy datatable data into sqlserver existing table.I''ve tried different approaches I found on the web but none of them works for my case :(
Here is the latest approach i used for which I get "An unhandled exception of type ''System.Data.SqlClient.SqlException'' occurred in System.Data .dll" error.
Your help is much appreciated
string connectionString = "server=localhost;database=CPSdata;Trusted_Connection=True"; ;
//Open a connection with destination database;
using (SqlConnection connection = new SqlConnection(connectionString))
{
connection.Open();
using (SqlBulkCopy bulkcopy = new SqlBulkCopy(connection))
{
bulkcopy.DestinationTableName = "dbo.climateRawDataTable";
try
{
bulkcopy.WriteToServer(dt);
}
catch (Exception ex)
{
}
connection.Close();
}
}
推荐答案
查看异常-在调试器中,或者通过添加try-catch块.该消息和任何内部异常详细信息应有助于对其进行跟踪.目前,我们只是在猜测-您没有提供足够的信息来解决问题.
Look at the exception - either in the debuggger, or by7 adding a try-catch block. The message and any inner exception details should help to track it. at the moment, we would be just guessing - you have given no where near enough information to solve the problem.
这篇关于将数据表数据传输到SQLserver的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文