批量插入问题与SqlBulkCopy. [英] Batch Insert Problem with SqlBulkCopy.

查看:111
本文介绍了批量插入问题与SqlBulkCopy.的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好,我有 access 数据库作为客户端数据库,而 sql server 数据库作为Web数据库.两个数据库的所有结构均相同除PK 以外,在sql服务器中 PK是uniqueidentifier ,在访问中, PK是文本(最大长度为255) .

在客户端应用程序中,我想通过 SqlBulkCopy 类将一些数据从客户端发送到Web(对sql的访问),为此,我使用此代码传输数据:

Hi
i have access db as client db and sql server db as web db. all structures of two database is same except PKs, in sql server PK is uniqueidentifier and in access, PK is Text (with 255 max Length).

in client app i want to send some data from client to web(access to sql) via SqlBulkCopy class, to do this, i use this code to transfer data :

this.personsTableAdapter1.Fill(this.testDataSet1.Persons);

DataTable dtImported = this.testDataSet1.Persons.Clone();

// because PK dataType in sql server is uniqueidentifier, hence i convert PK column to guid
dtImported.Columns["PersonID"].DataType = typeof(Guid);
foreach (TestDataSet.PersonsRow row in this.testDataSet1.Persons.Rows)
{
Guid g = new Guid(row.PersonID);
dtImported.Rows.Add(new object[] { g, row.PersonName }); // Error occur
}

System.Data.SqlClient.SqlBulkCopy bc = new System.Data.SqlClient.SqlBulkCopy(Properties.Settings.Default.TestSqlConnectionString);
bc.DestinationTableName = "Persons";
bc.WriteToServer(dtImported);



,但是在运行时,以下代码行向我显示了以下错误:



but at runTime the following error show me in above line of code:

Cannot set column 'PersonID'. The value violates the MaxLength limit of this column.



我的问题在哪里以及如何解决?


这是我的签名



where does my problem and how to solve it ?
Thanks


this is my Signature

推荐答案

有帮助吗?


这篇关于批量插入问题与SqlBulkCopy.的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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