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
  • 相关阅读:
    经典哦,男女3.8,8.3
    在web窗体设计器中未能加载该文件
    使用客户端脚本
    C#的数据类型
    实验下cookie
    C#中Split分隔字符串的应用
    未将对象引用设置到对象的实例
    System.StackOverflowException 的异常;jit调试失败
    DataGrid中添加删除确认对话框 多种实现
    常用正则表达式
  • 原文地址:https://www.cnblogs.com/junhuang/p/9416922.html
Copyright © 2011-2022 走看看