注册

.NET驱动,批量插入数据为null

I BELIEVE🚴🏼 2023/04/23 891 2

为提高效率,提问时请提供以下信息,问题描述清晰可优先响应。
【DM版本】:DM8(–03134283938-20221019-172201-20018)
【操作系统】:windows 10 64位
【CPU】:i5-10500
【问题描述】*:
驱动版本:DmProvider.1.1.0.16907

现象
使用DmBulkCopy批量插入,实体类和数据库字段大小写不一致数据为null, 上一版驱动1.1.0.16649无此问题
image.png

示例代码

//建表
 CREATE TABLE "ERP_CONFIG"."BULKCOPYTEST"
(
"NAME" VARCHAR(128),
"CODE" VARCHAR(512),
"ID" CHAR(36) NOT NULL,
"TYPE" VARCHAR(50),
NOT CLUSTER PRIMARY KEY("ID")) STORAGE(ON "MAIN", CLUSTERBTR) ;
//实体类
  internal class BULKCOPYTEST
    {

        public Guid Id { get; set; }
         
        public string Name { get; set; }
         
        public string Code { get; set; }

        public string Type { get; set; }
    }
//批量插入
internal static void LaunchBulkCopy1()
        {
            const string tableName = "BULKCOPYTEST";
            var entities = Enumerable.Range(1, 10).Select(x =>
                new BULKCOPYTEST()
                {
                    Code = $"code{x}",
                    Id = Guid.NewGuid(),
                    Name = $"name{x}",
                    Type = $"type{x}"
                });

            var dataTable = ToDataTable(entities.ToList());

            using (var connection = new DmConnection(s_connectionString))
            {
                connection.Open();

                using (var bulkCopy = new DmBulkCopy(connection))
                {
                    //设置插入的目标表
                    bulkCopy.DestinationTableName = tableName;

                    //DataTable列名与数据库列名的映射
                    for (int i = 0; i < dataTable.Columns.Count; i++)
                    {
                        bulkCopy.ColumnMappings.Add(dataTable.Columns[i].ColumnName, dataTable.Columns[i].ColumnName);
                    }
                    //写入数据库
                    bulkCopy.WriteToServer(dataTable); //System.AccessViolationException:“Attempted to read or write protected memory. This is often an indication that other memory is corrupt.”
                }
            }
        }
回答 0
暂无回答
扫一扫
联系客服