zoukankan      html  css  js  c++  java
  • Dapper操作

      public const string connString = "Data Source=.;Initial Catalog=test;User ID=sa;Password='qq'";
    
            private void dapperTest_Click(object sender, EventArgs e)
            {
                using (  SqlConnection conn = new SqlConnection(connString))
                {
                    string query = "SELECT * FROM Sys_Users WHERE id = @id";
                    List<User> list = conn.Query<User>(query, new { id = 100 }).ToList(); 
                }
            }
    
            private void dapperAdd_Click(object sender, EventArgs e)
            {
                int sqlResult = 0;
                User addModel = new User() { ID = 133, Age = 133, DepartmentID = 1, Name = "张三" };
                string sqlStr = "insert into sys_users(id,age,DepartmentID,name) values(@id,@age,@DepartmentID,@name)";
                using (SqlConnection conn = new SqlConnection(connString))
                {
                    sqlResult = conn.Execute(sqlStr,addModel);
                   
                }
         
            }
    
            private void dapperUpdate_Click(object sender, EventArgs e)
            {
                int sqlResult = 0;
                User addModel = new User() { ID = 133, Name = "栗色" };
                string sqlStr = "update  sys_users set  name=@name where id=@id";
                using (SqlConnection conn = new SqlConnection(connString))
                {
                    sqlResult = conn.Execute(sqlStr, addModel);
    
                }
            }
    
            private void dapperDelete_Click(object sender, EventArgs e)
            {
                int sqlResult = 0;
                User addModel = new User() { ID = 133};
                string sqlStr = "delete from sys_users where id=@id";
                using (SqlConnection conn = new SqlConnection(connString))
                {
                    sqlResult = conn.Execute(sqlStr, addModel);
    
                }
            }
        
    
        public class User
        {
            public int ID { get; set; }
            public string Name { get; set; }
            public int Age { get; set; }
            public int DepartmentID { get; set; }
            public string DepartmentID_Desc { get; set; }
        }
    View Code
  • 相关阅读:
    php 观察者模式
    php 策略模式
    php 适配器模式
    php 单例模式
    程序员应该关注的行业网站
    Mysql 5.7 索引使用规则和设计优化
    Docker官方镜像源或阿里云镜像源加速解决pull过慢的问题
    MySQL 优化案例
    mysql优化count(*)查询语句
    Mysql超大分页优化处理
  • 原文地址:https://www.cnblogs.com/junhuang/p/9416922.html
Copyright © 2011-2022 走看看