zoukankan      html  css  js  c++  java
  • 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; }
        }
    }
  • 相关阅读:
    子程序定义-3
    子程序定义-2
    子程序定义-1
    MQ报 AMQ9259
    观nginx与lvs负载均衡的较量
    绑定变量值长度不一致,mismatch问题
    perl-printf 函数
    perl 运算符
    强制让SQL走谓词推入
    PGA概念
  • 原文地址:https://www.cnblogs.com/sxjljj/p/11374096.html
Copyright © 2011-2022 走看看