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[];
model.Name = tempstr[];
model.Time =Convert.ToDateTime(tempstr[]);
model.Company = tempstr[];
models.Add(model);
}
return models;
}
上一篇:HMM模型详解


下一篇:怎么将unbuntu Linux iOS 文件从U盘或者移动硬盘启动?用win32diskimager_cn