예제 #1
0
        /// <summary>
        /// 增加一条数据
        /// </summary>
        public int Add(ZQUSR.Model.sr_ZhiCheng model)
        {
            StringBuilder strSql = new StringBuilder();

            strSql.Append("insert into sr_ZhiCheng(");
            strSql.Append("Grade,ZhiChengName)");
            strSql.Append(" values (");
            strSql.Append("@Grade,@ZhiChengName)");
            strSql.Append(";select @@IDENTITY");
            SqlParameter[] parameters =
            {
                new SqlParameter("@Grade",        SqlDbType.NVarChar, 10),
                new SqlParameter("@ZhiChengName", SqlDbType.NVarChar, 50)
            };
            parameters[0].Value = model.Grade;
            parameters[1].Value = model.ZhiChengName;

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

            if (obj == null)
            {
                return(0);
            }
            else
            {
                return(Convert.ToInt32(obj));
            }
        }
예제 #2
0
        /// <summary>
        /// 更新一条数据
        /// </summary>
        public bool Update(ZQUSR.Model.sr_ZhiCheng model)
        {
            StringBuilder strSql = new StringBuilder();

            strSql.Append("update sr_ZhiCheng set ");
            strSql.Append("Grade=@Grade,");
            strSql.Append("ZhiChengName=@ZhiChengName");
            strSql.Append(" where PK_ZCID=@PK_ZCID");
            SqlParameter[] parameters =
            {
                new SqlParameter("@PK_ZCID",      SqlDbType.Int,       4),
                new SqlParameter("@Grade",        SqlDbType.NVarChar, 10),
                new SqlParameter("@ZhiChengName", SqlDbType.NVarChar, 50)
            };
            parameters[0].Value = model.PK_ZCID;
            parameters[1].Value = model.Grade;
            parameters[2].Value = model.ZhiChengName;

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

            if (rows > 0)
            {
                return(true);
            }
            else
            {
                return(false);
            }
        }
예제 #3
0
        /// <summary>
        /// 得到一个对象实体
        /// </summary>
        public ZQUSR.Model.sr_ZhiCheng GetModel(int PK_ZCID)
        {
            StringBuilder strSql = new StringBuilder();

            strSql.Append("select  top 1 PK_ZCID,Grade,ZhiChengName from sr_ZhiCheng ");
            strSql.Append(" where PK_ZCID=@PK_ZCID");
            SqlParameter[] parameters =
            {
                new SqlParameter("@PK_ZCID", SqlDbType.Int, 4)
            };
            parameters[0].Value = PK_ZCID;

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

            if (ds.Tables[0].Rows.Count > 0)
            {
                if (ds.Tables[0].Rows[0]["PK_ZCID"].ToString() != "")
                {
                    model.PK_ZCID = int.Parse(ds.Tables[0].Rows[0]["PK_ZCID"].ToString());
                }
                model.Grade        = ds.Tables[0].Rows[0]["Grade"].ToString();
                model.ZhiChengName = ds.Tables[0].Rows[0]["ZhiChengName"].ToString();
                return(model);
            }
            else
            {
                return(null);
            }
        }
예제 #4
0
        /// <summary>
        /// 得到一个对象实体
        /// </summary>
        public ZQUSR.Model.sr_ZhiCheng GetModel(int PK_ZCID)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("select  top 1 PK_ZCID,Grade,ZhiChengName from sr_ZhiCheng ");
            strSql.Append(" where PK_ZCID=@PK_ZCID");
            SqlParameter[] parameters = {
                    new SqlParameter("@PK_ZCID", SqlDbType.Int,4)
            };
            parameters[0].Value = PK_ZCID;

            ZQUSR.Model.sr_ZhiCheng model = new ZQUSR.Model.sr_ZhiCheng();
            DataSet ds = DbHelperSQL.Query(strSql.ToString(), parameters);
            if (ds.Tables[0].Rows.Count > 0)
            {
                if (ds.Tables[0].Rows[0]["PK_ZCID"].ToString() != "")
                {
                    model.PK_ZCID = int.Parse(ds.Tables[0].Rows[0]["PK_ZCID"].ToString());
                }
                model.Grade = ds.Tables[0].Rows[0]["Grade"].ToString();
                model.ZhiChengName = ds.Tables[0].Rows[0]["ZhiChengName"].ToString();
                return model;
            }
            else
            {
                return null;
            }
        }