• Dapper


    vs2012,选择Dapper 1.50.2 版本,要不然可能会报上面的错误。

    https://www.cnblogs.com/huangxincheng/p/5828470.html

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using System.Threading.Tasks;
    using System.Data;
    using System.Data.SqlClient;
    using Dapper;
    
    namespace TestDapper
    {
        class Program
        {
            static void Main(string[] args)
            {
                string connectionStr = "Data Source=LJJ-FF\LJJ;Initial Catalog=TestDapper;User ID=sa;Password=111111;Max Pool Size=500;Min Pool Size=1";
                IDbConnection connection = new SqlConnection(connectionStr);
                //var result1 = connection.Execute("Insert into Users values (@UserName, @Email, @Address)",
                //                     new { UserName = "jack", Email = "380234234@qq.com", Address = "上海" });
    
                //var usersList = Enumerable.Range(0, 10).Select(i => new Users()
                //{
                //    Email = i + "qq.com",
                //    Address = "安徽",
                //    UserName = i + "jack"
                //});
    
                //var result2 = connection.Execute("Insert into Users values (@UserName, @Email, @Address)", usersList);
    
                //var query = connection.Query<Users>("select * from Users where UserName=@UserName", new { UserName = "jack" });
                //if (query != null)
                //{
                //    Console.WriteLine(((Users)query.FirstOrDefault()).UserName);
                   
                //}
    
                //var result3 = connection.Execute("update Users set UserName='nancy' where UserID=@UserID", new { UserID=11 });
                var result4 = connection.Execute("delete from Users where UserID=@UserID", new { UserID = 10});
                Console.ReadKey();
    
            }
        }
    
        class Users
        {
            public string UserID { get; set; }
            public string UserName { get; set; }
            public string Email { get; set; }
            public string Address { get; set; }
        }
    }
  • 相关阅读:
    组装query,query汇总,query字段
    POJ 1276, Cash Machine
    POJ 1129, Channel Allocation
    POJ 2531, Network Saboteur
    POJ 1837, Balance
    POJ 3278, Catch That Cow
    POJ 2676, Sudoku
    POJ 3126, Prime Path
    POJ 3414, Pots
    POJ 1426, Find The Multiple
  • 原文地址:https://www.cnblogs.com/sxjljj/p/11374096.html
Copyright © 2020-2023  润新知