• C# sqlhelper 通用类 实现方法


     public class Produce
        {
            #region 增加单条记录
            public static  int ProductAdd(produce product)
            {
                StringBuilder strSql = new StringBuilder();
                strSql.Append(" insert into  dbo.produce ( CategoryID,produceName,producePrice,produceStock,produceDescription)");
                strSql.Append(" values (@CategoryID,@produceName,@producePrice,@produceStock,@produceDescription)");
                SqlParameter[] parmaeter =    { 
                                           new SqlParameter("@CategoryID",SqlDbType.Int,4),
                                           new SqlParameter("@produceName",SqlDbType.VarChar,100),
                                           new SqlParameter("@producePrice",SqlDbType.Decimal,9),
                                           new SqlParameter("@produceStock",SqlDbType.Int,4),
                                           new SqlParameter("@produceDescription",SqlDbType.VarChar,200),
                                      
                                      
                                       };
                parmaeter[0].Value = product.CategoryID;
                parmaeter[1].Value = product.ProduceName;
                parmaeter[2].Value = product.ProducePrice;
                parmaeter[3].Value = product.ProduceStock;
                parmaeter[3].Value = product.ProduceDescription;
                return SQLHelper.ExecuteSql(strSql.ToString(), parmaeter);


            }
            #endregion

            #region 修改一条记录
            public static bool ProductUpdate(produce product)
            {
                bool isError = false;
                try
                {

                    StringBuilder strSql = new StringBuilder();
                    strSql.Append(" update  dbo.produce set CategoryID=@CategoryID,produceName=@produceName");
                    strSql.Append(" ,producePrice=@producePrice, produceStock=@produceStock,produceDescription=@produceDescription");
                    strSql.Append(" where produceID =6");
                    SqlParameter[] parmaeter =    { 
                                           new SqlParameter("@CategoryID",SqlDbType.Int,4),
                                           new SqlParameter("@produceName",SqlDbType.VarChar,100),
                                           new SqlParameter("@producePrice",SqlDbType.Decimal,9),
                                           new SqlParameter("@produceStock",SqlDbType.Int,4),
                                           new SqlParameter("@produceDescription",SqlDbType.VarChar,200),
                                      
                                      
                                       };
                    parmaeter[0].Value = product.CategoryID;
                    parmaeter[1].Value = product.ProduceName;
                    parmaeter[2].Value = product.ProducePrice;
                    parmaeter[3].Value = product.ProduceStock;
                    parmaeter[3].Value = product.ProduceDescription;
                    int i = SQLHelper.ExecuteSql(strSql.ToString(), parmaeter);
                    if (i > 0)
                    {
                        isError = true;
                    }
                }
                catch (Exception ex)
                {
                    isError = false;
                }
                return isError;

            }
            #endregion

            #region 得到一个实体
            public  static  produce GetproduceModel(int ID)
            {
                StringBuilder strSql = new StringBuilder();
                strSql.Append(" select top 1 * from dbo.View_Produce");
                strSql.Append(" where  produceID = " + ID + " ");
                // strSql.Append(" where  produceID = @produceID");
                //SqlParameter[] parameter = {
                //                           new SqlParameter("@produceID",SqlDbType.Int ,4)
                //                           };
                //   parameter[0].Value = ID;
                produce product = new produce();//实例化
                DataSet ds = SQLHelper.ExecuteDs(strSql.ToString());
                if (ds.Tables[0].Rows.Count > 0)
                {
                    if (ds.Tables[0].Rows[0]["produceID"].ToString() != null)
                    {
                        product.ProduceID = Convert.ToInt32(ds.Tables[0].Rows[0]["produceID"].ToString());
                    }
                    if (ds.Tables[0].Rows[0]["CategoryID"].ToString() != null)
                    {
                        product.CategoryID = Convert.ToInt32(ds.Tables[0].Rows[0]["CategoryID"].ToString());

                    }
                    product.ProduceName = ds.Tables[0].Rows[0]["produceName"].ToString();
                    product.ProducePrice = Convert.ToDecimal(ds.Tables[0].Rows[0]["producePrice"].ToString());
                    product.ProduceStock = Convert.ToInt32(ds.Tables[0].Rows[0]["produceStock"].ToString());
                    product.ProduceDescription = ds.Tables[0].Rows[0]["produceDescription"].ToString();

                }
                else
                {
                    return null;
                }
                return product;

            }
            #endregion

            #region 得到列表
            public  DataTable GetTable()
            {
                StringBuilder strSql = new StringBuilder();
                strSql.Append(" select top * from dbo.View_Produce");
                DataTable  ds = SQLHelper.ExecuteDt(strSql.ToString());
                return ds;
            }
            #endregion

        }

  • 相关阅读:
    phpcms 任意位置获取用户头像
    php微信公众帐号发送红包
    nginx解决502错误
    phpcms v9 万能字段使用
    0转换为万
    温故而知新(三)
    温故而知新(一)
    基础积累,来自其他网站的链接
    GCD多线程 在子线程中获取网络图片 在主线程更新
    iOS9 中的一些适配问题
  • 原文地址:https://www.cnblogs.com/dullbaby/p/2950020.html
Copyright © 2020-2023  润新知