示例#1
0
 public void Insert2()
 {
     for (int i = 2; i < 10; i++)
     {
         var model = new Account()
         {
             Id = i.ToString(),
             Name = "张三" + i.ToString(),
             Password = "******",
             Email = "*****@*****.**",
             CreateTime = DateTime.Now,
             Age = 15
         };
         using (var db = CreateConnection())
         {
           var result= db.Execute("INSERT INTO Account(Id,Name,Password,Email,CreateTime,Age) VALUES(@Id,@Name,@Password,@Email,@CreateTime,@Age)", model);
         }
     }
 }
示例#2
0
 public void Insert()
 {
     var model = new Account()
     {
         Id = "1",
         Name = "张三1",
         Password = "******",
         Email = "*****@*****.**",
         CreateTime = DateTime.Now,
         Age = 15
     };
     using (var db = CreateConnection())
     {
         var result = db.Execute("INSERT INTO Account(Id,Name,Password,Email,CreateTime,Age) VALUES(@Id,@Name,@Password,@Email,@CreateTime,@Age)", model);
         if (result==1)
             Console.WriteLine("添加成功");
         else
             Console.WriteLine("添加失败");
     }
 }
示例#3
0
 public void Insert()
 {
     var model = new Account()
     {
         Id = "1",
         Name = "张三1",
         Password = "******",
         Email = "*****@*****.**",
         CreateTime = DateTime.Now,
         Age = 15
     };
     using (var db = CreateDbBase())
     {
         var result = db.Insert<Account>(model);
         if (result)
             Console.WriteLine("添加成功");
         else
             Console.WriteLine("添加失败");
     }
 }
示例#4
0
 public void InsertBatch()
 {
     var list = new List<Account>();
     for (int i = 10; i < 21; i++)
     {
         var model = new Account()
         {
             Id = i.ToString(),
             Name = "张三" + i.ToString(),
             Password = "******",
             Email = "*****@*****.**",
             CreateTime = DateTime.Now,
             Age = 15
         };
         list.Add(model);
     }
     using (var db = CreateDbBase())
     {
         var result = db.InsertBatch<Account>(list);
         if (result)
             Console.WriteLine("添加成功");
         else
             Console.WriteLine("添加失败");
     }
 }
示例#5
0
        public void Insert3()
        {
            using (var db = CreateDbBase())
            {
                var tran = db.DbTransaction;
                for (int i = 2; i < 10; i++)
                {
                    var model = new Account()
                    {
                        Id = i.ToString(),
                        Name = "张三" + i.ToString(),
                        Password = "******",
                        Email = "*****@*****.**",
                        CreateTime = DateTime.Now,
                        Age = 15
                    };

                    var result = db.Insert<Account>(model,tran);

                }
                tran.Commit();
            }
        }
示例#6
0
 public void Insert2()
 {
     for (int i = 2; i < 10; i++)
     {
         var model = new Account()
         {
             Id = i.ToString(),
             Name = "张三" + i.ToString(),
             Password = "******",
             Email = "*****@*****.**",
             CreateTime = DateTime.Now,
             Age = 15
         };
         using (var db = CreateDbBase())
         {
             var result = db.Insert<Account>(model);
         }
     }
 }