Ejemplo n.º 1
0
        /// <summary>
        /// 得到一个对象实体
        /// </summary>
        public LearnSite.Model.House GetModel(int Hid)
        {
            StringBuilder strSql = new StringBuilder();

            strSql.Append("select  top 1 Hid,Hname,Hseat from House ");
            strSql.Append(" where Hid=@Hid");
            SqlParameter[] parameters =
            {
                new SqlParameter("@Hid", SqlDbType.Int, 4)
            };
            parameters[0].Value = Hid;

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

            if (ds.Tables[0].Rows.Count > 0)
            {
                if (ds.Tables[0].Rows[0]["Hid"].ToString() != "")
                {
                    model.Hid = int.Parse(ds.Tables[0].Rows[0]["Hid"].ToString());
                }
                model.Hname = ds.Tables[0].Rows[0]["Hname"].ToString();
                model.Hseat = ds.Tables[0].Rows[0]["Hseat"].ToString();
                return(model);
            }
            else
            {
                return(null);
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// 增加一条数据
        /// </summary>
        public int Add(LearnSite.Model.House model)
        {
            StringBuilder strSql = new StringBuilder();

            strSql.Append("insert into House(");
            strSql.Append("Hname,Hseat)");
            strSql.Append(" values (");
            strSql.Append("@Hname,@Hseat)");
            strSql.Append(";select @@IDENTITY");
            SqlParameter[] parameters =
            {
                new SqlParameter("@Hname", SqlDbType.NVarChar, 50),
                new SqlParameter("@Hseat", SqlDbType.NText)
            };
            parameters[0].Value = model.Hname;
            parameters[1].Value = model.Hseat;

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

            if (obj == null)
            {
                return(0);
            }
            else
            {
                return(Convert.ToInt32(obj));
            }
        }
Ejemplo n.º 3
0
        /// <summary>
        /// 更新一条数据
        /// </summary>
        public bool Update(LearnSite.Model.House model)
        {
            StringBuilder strSql = new StringBuilder();

            strSql.Append("update House set ");
            strSql.Append("Hname=@Hname,");
            strSql.Append("Hseat=@Hseat");
            strSql.Append(" where Hid=@Hid");
            SqlParameter[] parameters =
            {
                new SqlParameter("@Hname", SqlDbType.NVarChar, 50),
                new SqlParameter("@Hseat", SqlDbType.NText),
                new SqlParameter("@Hid",   SqlDbType.Int, 4)
            };
            parameters[0].Value = model.Hname;
            parameters[1].Value = model.Hseat;
            parameters[2].Value = model.Hid;

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

            if (rows > 0)
            {
                return(true);
            }
            else
            {
                return(false);
            }
        }