dapper实现增删改查

使用前要安装:// Install-Package Dapper

//查询


           
           
           
               

                   
                   
                   
                   
               
           
       
       
名字:年龄:电话:
<%#Eval("Name") %><%#Eval("Age") %><%#Eval("Phone") %>
                        修改
                        删除
                       
                   

        添加

//查询后台:

IDbConnection connection = new SqlConnection("Data Source=PC201808041053\\SQLEXPRESS;uid=sa;pwd=sa;Initial Catalog=Pachong;Integrated Security=True;MultipleActiveResultSets=True");

            var query = connection.Query("select * from UserBiao");
            xianshi.DataSource = query;
            xianshi.DataBind();

//删除后台:

int ID=Convert.ToInt32((e.Item.FindControl("ssssss") as HiddenField).Value);
            if (e.CommandName == "Delete")
            {
                IDbConnection connection = new SqlConnection("Data Source=PC201808041053\\SQLEXPRESS;uid=sa;pwd=sa;Initial Catalog=Pachong;Integrated Security=True;MultipleActiveResultSets=True");
                var result = connection.Execute("delete from UserBiao where Id=@Id", new { Id = ""+ID+""});
            }
            else  {Response.Redirect("UpdatePage.aspx?UpdateID=" + ID);}

//添加

名字:

        年龄:

        电话

       

//添加后台:

string Mingzi = txtName.Text.Trim();
string NianLing = txtAge.Text.Trim();
string DianHua = txtPhone.Text.Trim();

IDbConnection connection = new SqlConnection("Data Source=PC201808041053\\SQLEXPRESS;uid=sa;pwd=sa;Initial Catalog=Pachong;Integrated Security=True;MultipleActiveResultSets=True");
var result = connection.Execute("Insert into UserBiao values (@Name, @Age, @Phone)", new { Name = "" + Mingzi + "", Age = "" + NianLing + "", Phone = "" + DianHua + "" });

//编辑暂时没有

你可能感兴趣的:(dapper实现增删改查)