コード例 #1
0
        /// <summary>
        /// 更新一条数据
        /// </summary>
        public bool Update(Maticsoft.Model.photos model)
        {
            StringBuilder strSql = new StringBuilder();

            strSql.Append("update photos set ");
            strSql.Append("ContentType=@ContentType,");
            strSql.Append("postedFileFileName=@postedFileFileName,");
            strSql.Append("FileName=@FileName,");
            strSql.Append("fileExtension=@fileExtension,");
            strSql.Append("qishu=@qishu,");
            strSql.Append("fenlei2=@fenlei2");
            strSql.Append(" where id=@id");
            SqlParameter[] parameters =
            {
                new SqlParameter("@ContentType",        SqlDbType.NVarChar, 50),
                new SqlParameter("@postedFileFileName", SqlDbType.NVarChar, 50),
                new SqlParameter("@FileName",           SqlDbType.NVarChar, 50),
                new SqlParameter("@fileExtension",      SqlDbType.NVarChar, 50),
                new SqlParameter("@qishu",              SqlDbType.NVarChar, 50),
                new SqlParameter("@fenlei2",            SqlDbType.NVarChar, 50),
                new SqlParameter("@id",                 SqlDbType.Int, 4)
            };
            parameters[0].Value = model.ContentType;
            parameters[1].Value = model.postedFileFileName;
            parameters[2].Value = model.FileName;
            parameters[3].Value = model.fileExtension;
            parameters[4].Value = model.qishu;
            parameters[5].Value = model.fenlei2;
            parameters[6].Value = model.id;

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

            if (rows > 0)
            {
                return(true);
            }
            else
            {
                return(false);
            }
        }
コード例 #2
0
 /// <summary>
 /// 得到一个对象实体
 /// </summary>
 public Maticsoft.Model.photos DataRowToModel(DataRow row)
 {
     Maticsoft.Model.photos model = new Maticsoft.Model.photos();
     if (row != null)
     {
         if (row["id"] != null && row["id"].ToString() != "")
         {
             model.id = int.Parse(row["id"].ToString());
         }
         if (row["ContentType"] != null)
         {
             model.ContentType = row["ContentType"].ToString();
         }
         if (row["postedFileFileName"] != null)
         {
             model.postedFileFileName = row["postedFileFileName"].ToString();
         }
         if (row["FileName"] != null)
         {
             model.FileName = row["FileName"].ToString();
         }
         if (row["fileExtension"] != null)
         {
             model.fileExtension = row["fileExtension"].ToString();
         }
         if (row["qishu"] != null)
         {
             model.qishu = row["qishu"].ToString();
         }
         if (row["fenlei2"] != null)
         {
             model.fenlei2 = row["fenlei2"].ToString();
         }
     }
     return(model);
 }
コード例 #3
0
        /// <summary>
        /// 增加一条数据
        /// </summary>
        public int Add(Maticsoft.Model.photos model)
        {
            StringBuilder strSql = new StringBuilder();

            strSql.Append("insert into photos(");
            strSql.Append("ContentType,postedFileFileName,FileName,fileExtension,qishu,fenlei2)");
            strSql.Append(" values (");
            strSql.Append("@ContentType,@postedFileFileName,@FileName,@fileExtension,@qishu,@fenlei2)");
            strSql.Append(";select @@IDENTITY");
            SqlParameter[] parameters =
            {
                new SqlParameter("@ContentType",        SqlDbType.NVarChar, 50),
                new SqlParameter("@postedFileFileName", SqlDbType.NVarChar, 50),
                new SqlParameter("@FileName",           SqlDbType.NVarChar, 50),
                new SqlParameter("@fileExtension",      SqlDbType.NVarChar, 50),
                new SqlParameter("@qishu",              SqlDbType.NVarChar, 50),
                new SqlParameter("@fenlei2",            SqlDbType.NVarChar, 50)
            };
            parameters[0].Value = model.ContentType;
            parameters[1].Value = model.postedFileFileName;
            parameters[2].Value = model.FileName;
            parameters[3].Value = model.fileExtension;
            parameters[4].Value = model.qishu;
            parameters[5].Value = model.fenlei2;

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

            if (obj == null)
            {
                return(0);
            }
            else
            {
                return(Convert.ToInt32(obj));
            }
        }
コード例 #4
0
        /// <summary>
        /// 得到一个对象实体
        /// </summary>
        public Maticsoft.Model.photos GetModel(int id)
        {
            StringBuilder strSql = new StringBuilder();

            strSql.Append("select  top 1 id,ContentType,postedFileFileName,FileName,fileExtension,qishu,fenlei2 from photos ");
            strSql.Append(" where id=@id");
            SqlParameter[] parameters =
            {
                new SqlParameter("@id", SqlDbType.Int, 4)
            };
            parameters[0].Value = id;

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

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