使用db.Insertable(list).UseMySql().ExecuteBlueCopy();反馈 返回

C#论坛 老数据
6 1760

版本:5.0.2.6

批量导入数据库,导入后的数据第一行第一列中数据开头多出一个不可见字符,字符值为65279。数据无法关联

下面是我的修改方式,改完后数据正常,不知这个方式是否修改的正确方式。new UTF8Encoding(false));//保存无BOM的UTF8格式

QQ图片20210317144245.png

热忱回答6

  • 你这种可以写个DEMO给我,一般很难重现

    0 回复
  • cfc1689 cfc1689 VIP0
    2021/3/17

    @fate stay night

     internal class Program

        {

            private static void Main(string[] args)

            {

                var db = new SqlSugarClient(new ConnectionConfig()

                {

                    ConnectionString = "server=192.168.8.188;port=3306;user id=root;password=123456;database=abc; pooling=true;AllowLoadLocalInfile=true;",

                    DbType = DbType.MySql,

                    IsAutoCloseConnection = true,

                });


                var list = new List<testdb>();


                for (int i = 0; i < 10; i++)

                {

                    var id = i.ToString();

                    list.Add(new testdb

                    {

                        id = id,

                    });

                    Console.WriteLine(id + " Length:" + id.Length);

                }


                db.Insertable(list).UseMySql().ExecuteBlueCopy();


                var queryList = db.Queryable<testdb>().ToList();


                foreach (var item in queryList)

                {

                    if (item.id.Length != 1)

                    {

                        Console.WriteLine(item.id + " Length:" + item.id.Length);//这个地方0的长度变了,前面有空字符,就添加的第一个会,数据库字段id字符集是utf8,字段类型varchar

                    }

                }


                Console.WriteLine("执行完成");

                Console.ReadKey();

            }


            public class testdb

            {

                public string id { get; set; }

            }

        }


    0 回复
  • @cfc1689:好的记下来了 

    0 回复
  • 建表语句最好也发一下

    0 回复
  • cfc1689 cfc1689 VIP0
    2021/3/17

    @fate stay night

    CREATE TABLE IF NOT EXISTS `testdb`(  

       `id` VARCHAR(50) NOT NULL

    )


    0 回复
  • 明天更新到NUGET

    0 回复