zoukankan      html  css  js  c++  java
  • MVC简单增删改

    /// <summary>
    /// /显示分页
    /// </summary>
    /// <param name="model"></param>
    /// <returns></returns>
    public PagesOut<Stu> GetDataList(ProcPrams model)
    {
    SqlParameter[] pam =
    {
    new SqlParameter("@TableName",model.TableName),
    new SqlParameter("@indexCol",model.IndexCol),
    new SqlParameter("@PageSize",model.PageSize),
    new SqlParameter("@PageIndex",model.PageIndex),
    new SqlParameter("@OrderCol",model.OrderCol),
    new SqlParameter("@Where",model.Where),
    new SqlParameter("@Columns",model.Columns),

    };

    DataSet ds = DbHelperSQL.ExecuteDataset(DbHelperSQL.ConnB2c, CommandType.StoredProcedure, "p_paging", pam);
    var list = JsonConvert.DeserializeObject<List<Stu>>(JsonConvert.SerializeObject(ds.Tables[0]));
    PagesOut<Stu> lis = new PagesOut<Stu>();
    lis.list = list;

    lis.SumCount = Convert.ToInt32(ds.Tables[1].Rows[0][0]);
    return lis;
    }

    /// <summary>
    /// 添加
    /// </summary>
    /// <param name="model"></param>
    /// <returns></returns>
    public int InsertData(Stu model)
    {

    SqlParameter[] pam =
    {
    new SqlParameter("@Name",model.Name),
    new SqlParameter("@Age",model.Age),
    new SqlParameter("@Sex",model.Sex),
    new SqlParameter("@StatId",model.StatId),
    };

    int i = DbHelperSQL.ExecuteNonQuery(DbHelperSQL.ConnB2c, CommandType.StoredProcedure, "p_Add", pam);
    return i;
    }

    /// <summary>
    /// 删除
    /// </summary>
    /// <param name="id"></param>
    /// <returns></returns>
    public int DeleteData(int id)
    {

    SqlParameter[] pam =
    {
    new SqlParameter("@ID",id)
    };

    int i = DbHelperSQL.ExecuteNonQuery(DbHelperSQL.ConnB2c, CommandType.StoredProcedure, "p_Del", pam);
    return i;
    }

    //根据id获取
    public Stu GetId(int id)
    {
    string sql = "select * from Stu where ID=" + id;
    DataTable dt = DbHelperSQL.ExecuteDataTable(DbHelperSQL.ConnB2c, CommandType.Text, sql, null);
    List<Stu> list = JsonConvert.DeserializeObject<List<Stu>>(JsonConvert.SerializeObject(dt));
    return list.FirstOrDefault();
    }

    /// <summary>
    /// 修改
    /// </summary>
    /// <param name="model"></param>
    /// <returns></returns>
    public int UpdataData(Stu model)
    {

    SqlParameter[] pam =
    {
    new SqlParameter("@ID",model.ID),
    new SqlParameter("@Name",model.Name),
    new SqlParameter("@Age",model.Age),
    new SqlParameter("@Sex",model.Sex),
    new SqlParameter("@StatId",model.StatId),
    };

    int i = DbHelperSQL.ExecuteNonQuery(DbHelperSQL.ConnB2c, CommandType.StoredProcedure, "p_update", pam);
    return i;
    }

  • 相关阅读:
    .NET中TreeView控件从数据库获取数据源
    .NET中GridView控件的全选删除
    TreeView无限极分类绑定(从数据库读取数据源)
    .NET中GridView代码更改列名
    .NET读写cookie方法
    .NET中GridView控件的高亮显示和删除前弹框提示
    Repeater控件的多层嵌套,DataList控件的多层嵌套
    .NET一些常用的语句集合(不断更新中)
    解决IE5、IE6、IE7与W3C标准的冲突,使用(IE7.js IE8.js)兼容
    kindeditor富文本编辑器ASP.NET源码下载
  • 原文地址:https://www.cnblogs.com/xiaoandong/p/9388652.html
Copyright © 2011-2022 走看看