zoukankan      html  css  js  c++  java
  • c#传入类名插入多条数据

    public int Insert<T>(IReadOnlyCollection<T> models)
    where T : class, new()
    {
    int sucess = 0;
    if (models.Count > 0)
    {
    foreach (var model in models)
    {
    string name = model.GetType().Name;
    if (name.Equals("TempInfo"))
    {
    TempInfo temp = (TempInfo)(object)model;
    sucess = InsertUser(temp);
    }
    }
    }
    return sucess;
    }

    private int InsertUser(TempInfo temp)
    {
    int sucess = 0;
    using (EFEntity ef = new EFEntity())
    {
    ef.TempInfo.Add(temp);
    sucess = ef.SaveChanges();
    }
    return sucess;
    }

    int sucess = 0;
    EFEntity entity = new EFEntity();
    InsertOprater oprator = new InsertOprater();
    IReadOnlyCollection<TempInfo> list = new Collection<TempInfo>() {
    new TempInfo(){
    Name = "123",
    Age = 1,
    Address = "沈阳市",
    Phone = "13578907890",
    condition = "测试"
    },
    new TempInfo(){
    Name = "1234",
    Age = 2,
    Address = "沈阳市吧",
    Phone = "13012345678",
    condition = "测试2"
    },
    new TempInfo(){
    Name = "12345",
    Age = 3,
    Address = "本溪市",
    Phone = "13409876543",
    condition = "测试3"
    }
    };
    sucess = oprator.Insert(list);
    if (sucess > 0)
    {
    MessageBox.Show("添加数据模块成功!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
    }
    else
    {
    MessageBox.Show("添加数据模块失败!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
    }

  • 相关阅读:
    安卓学习Day11
    J2EE-Day09-Servlet
    J2EE-Day08-Tomcat
    安卓学习Day10
    安卓学习Day09
    安卓学习Day08
    安卓学习Day07
    安卓学习Day06
    YII 1.0 常用CURD写法
    php 封装原生数据导出的方法(csv文件格式)和csv文件中长数字自动变成科学计数法的处理
  • 原文地址:https://www.cnblogs.com/missheyo/p/11189524.html
Copyright © 2011-2022 走看看