Ejemplo n.º 1
0
        /// <summary>
        /// 更新一条数据
        /// </summary>
        public bool Update(MesWeb.Model.ProductType model)
        {
            StringBuilder strSql = new StringBuilder();

            strSql.Append("update ProductType set ");
            strSql.Append("productName=SQL2012productName");
            strSql.Append(" where id=SQL2012id");
            SqlParameter[] parameters =
            {
                new SqlParameter("SQL2012productName", SqlDbType.NVarChar, 30),
                new SqlParameter("SQL2012id",          SqlDbType.Int, 4)
            };
            parameters[0].Value = model.productName;
            parameters[1].Value = model.id;

            int rows = DbHelperSQL.ExecuteSql(strSql.ToString(), parameters);

            if (rows > 0)
            {
                return(true);
            }
            else
            {
                return(false);
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// 增加一条数据
        /// </summary>
        public int Add(MesWeb.Model.ProductType model)
        {
            StringBuilder strSql = new StringBuilder();

            strSql.Append("insert into ProductType(");
            strSql.Append("productName)");
            strSql.Append(" values (");
            strSql.Append("SQL2012productName)");
            strSql.Append(";select @@IDENTITY");
            SqlParameter[] parameters =
            {
                new SqlParameter("SQL2012productName", SqlDbType.NVarChar, 30)
            };
            parameters[0].Value = model.productName;

            object obj = DbHelperSQL.GetSingle(strSql.ToString(), parameters);

            if (obj == null)
            {
                return(0);
            }
            else
            {
                return(Convert.ToInt32(obj));
            }
        }
Ejemplo n.º 3
0
 /// <summary>
 /// 得到一个对象实体
 /// </summary>
 public MesWeb.Model.ProductType DataRowToModel(DataRow row)
 {
     MesWeb.Model.ProductType model = new MesWeb.Model.ProductType();
     if (row != null)
     {
         if (row["id"] != null && row["id"].ToString() != "")
         {
             model.id = int.Parse(row["id"].ToString());
         }
         if (row["productName"] != null)
         {
             model.productName = row["productName"].ToString();
         }
     }
     return(model);
 }
Ejemplo n.º 4
0
        /// <summary>
        /// 得到一个对象实体
        /// </summary>
        public MesWeb.Model.ProductType GetModel(int id)
        {
            StringBuilder strSql = new StringBuilder();

            strSql.Append("select  top 1 id,productName from ProductType ");
            strSql.Append(" where id=SQL2012id");
            SqlParameter[] parameters =
            {
                new SqlParameter("SQL2012id", SqlDbType.Int, 4)
            };
            parameters[0].Value = id;

            MesWeb.Model.ProductType model = new MesWeb.Model.ProductType();
            DataSet ds = DbHelperSQL.Query(strSql.ToString(), parameters);

            if (ds.Tables[0].Rows.Count > 0)
            {
                return(DataRowToModel(ds.Tables[0].Rows[0]));
            }
            else
            {
                return(null);
            }
        }