zoukankan      html  css  js  c++  java
  • Dapper批量添加

    Public void Add()
    {
     List<PPQuery> lists = GetDataByFile(tempFilePath);
    private static readonly string sqlconnection = "Data Source=.;Initial Catalog=xxxx;Persist Security Info=True;User ID=sa;Password=123"; using (var connection = new System.Data.SqlClient.SqlConnection(sqlconnection)) { resultData = connection.Execute("Insert into [PPQuery] values (@ID,@Name,@Time,@Company)", lists); } }
       public List<PPQuery> GetDataByFile(string path)
            {
                var file = File.Open(path, FileMode.Open);
                List<string> txt = new List<string>();
                using (var stream = new StreamReader(file, System.Text.Encoding.GetEncoding("utf-8")))
                {
                    while (!stream.EndOfStream)
                    {
                        txt.Add(stream.ReadLine());
                    }
                }
                file.Close();
                List<PPQuery> models = new List<PPQuery>();
                //循环list
                foreach (string item in txt)
                {
                    string[] tempstr = item.Split(',');
                    PPQuery model = new PPQuery();
                    model.ID = tempstr[0];
                    model.Name = tempstr[1];
                    model.Time =Convert.ToDateTime(tempstr[2]);
                    model.Company = tempstr[3];
                    models.Add(model);
                }
                return models;
            }
  • 相关阅读:
    线程原理 创建方式
    Chapter17 【异常、线程】
    驱动
    java中Super到底是什么意思
    Java 8后的首个长期支持版本Java 11
    OpenJDK和JDK区别
    异常
    模拟斗地主洗牌发牌
    Debug追踪
    Python 垃圾回收机制详细
  • 原文地址:https://www.cnblogs.com/25miao/p/7206960.html
Copyright © 2011-2022 走看看