• 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
  • 相关阅读:
    操作系统,,,也考完了【流坑】
    认真地搭建python开发环境
    NumPy 上手一个例子 vectorsum.py
    数字图像处理、、考完了
    Intel系列CPU的流水线技术的发展
    JSON序列化为实体对象
    一个丝滑的全屏滑动返回手势
    Swift项目兼容Objective-C问题汇总
    OC 九宫格布局
    SDWebImage 新版接口使用方法
  • 原文地址:https://www.cnblogs.com/junhuang/p/9416922.html
Copyright © 2020-2023  润新知