Beispiel #1
0
        /// <summary>
        /// 更新一条数据
        /// </summary>
        public bool Update(lgk.Model.tb_city model)
        {
            StringBuilder strSql = new StringBuilder();

            strSql.Append("update tb_city set ");
            strSql.Append("id=@id,");
            strSql.Append("cityID=@cityID,");
            strSql.Append("city=@city,");
            strSql.Append("father=@father");
            strSql.Append(" where ");
            SqlParameter[] parameters =
            {
                new SqlParameter("@id",     SqlDbType.Int,       4),
                new SqlParameter("@cityID", SqlDbType.NVarChar,  6),
                new SqlParameter("@city",   SqlDbType.NVarChar, 50),
                new SqlParameter("@father", SqlDbType.NVarChar, 6)
            };
            parameters[0].Value = model.id;
            parameters[1].Value = model.cityID;
            parameters[2].Value = model.city;
            parameters[3].Value = model.father;

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

            if (rows > 0)
            {
                return(true);
            }
            else
            {
                return(false);
            }
        }
Beispiel #2
0
        /// <summary>
        /// 增加一条数据
        /// </summary>
        public void Add(lgk.Model.tb_city model)
        {
            StringBuilder strSql = new StringBuilder();

            strSql.Append("insert into tb_city(");
            strSql.Append("id,cityID,city,father)");
            strSql.Append(" values (");
            strSql.Append("@id,@cityID,@city,@father)");
            SqlParameter[] parameters =
            {
                new SqlParameter("@id",     SqlDbType.Int,       4),
                new SqlParameter("@cityID", SqlDbType.NVarChar,  6),
                new SqlParameter("@city",   SqlDbType.NVarChar, 50),
                new SqlParameter("@father", SqlDbType.NVarChar, 6)
            };
            parameters[0].Value = model.id;
            parameters[1].Value = model.cityID;
            parameters[2].Value = model.city;
            parameters[3].Value = model.father;

            DbHelperSQL.ExecuteSql(strSql.ToString(), parameters);
        }
Beispiel #3
0
        /// <summary>
        /// 得到一个对象实体
        /// </summary>
        public lgk.Model.tb_city GetModel(string strWhere)
        {
            //该表无主键信息,请自定义主键/条件字段
            StringBuilder strSql = new StringBuilder();

            strSql.Append("select  top 1 id,cityID,city,father from tb_city ");
            if (strWhere.Trim() != "")
            {
                strSql.Append(" where " + strWhere);
            }

            lgk.Model.tb_city model = new lgk.Model.tb_city();
            DataSet           ds    = DbHelperSQL.Query(strSql.ToString());

            if (ds.Tables[0].Rows.Count > 0)
            {
                if (ds.Tables[0].Rows[0]["id"] != null && ds.Tables[0].Rows[0]["id"].ToString() != "")
                {
                    model.id = int.Parse(ds.Tables[0].Rows[0]["id"].ToString());
                }
                if (ds.Tables[0].Rows[0]["cityID"] != null && ds.Tables[0].Rows[0]["cityID"].ToString() != "")
                {
                    model.cityID = ds.Tables[0].Rows[0]["cityID"].ToString();
                }
                if (ds.Tables[0].Rows[0]["city"] != null && ds.Tables[0].Rows[0]["city"].ToString() != "")
                {
                    model.city = ds.Tables[0].Rows[0]["city"].ToString();
                }
                if (ds.Tables[0].Rows[0]["father"] != null && ds.Tables[0].Rows[0]["father"].ToString() != "")
                {
                    model.father = ds.Tables[0].Rows[0]["father"].ToString();
                }
                return(model);
            }
            else
            {
                return(null);
            }
        }