Example #1
0
        /// <summary>
        /// 获得数据列表
        /// </summary>
        public List <System.Model.t_city2> DataTableToList(DataTable dt)
        {
            List <System.Model.t_city2> modelList = new List <System.Model.t_city2>();
            int rowsCount = dt.Rows.Count;

            if (rowsCount > 0)
            {
                System.Model.t_city2 model;
                for (int n = 0; n < rowsCount; n++)
                {
                    model = new System.Model.t_city2();
                    if (dt.Rows[n]["id"].ToString() != "")
                    {
                        model.id = int.Parse(dt.Rows[n]["id"].ToString());
                    }
                    model.cityID = dt.Rows[n]["cityID"].ToString();
                    model.city   = dt.Rows[n]["city"].ToString();
                    model.father = dt.Rows[n]["father"].ToString();


                    modelList.Add(model);
                }
            }
            return(modelList);
        }
Example #2
0
        /// <summary>
        /// 更新一条数据
        /// </summary>
        public bool Update(System.Model.t_city2 model)
        {
            StringBuilder strSql = new StringBuilder();

            strSql.Append("update t_city2 set ");

            strSql.Append(" id = @id , ");
            strSql.Append(" cityID = @cityID , ");
            strSql.Append(" city = @city , ");
            strSql.Append(" father = @father  ");
            strSql.Append(" where id=@id  ");

            SqlParameter[] parameters =
            {
                new SqlParameter("@id",     SqlDbType.Int,       4),
                new SqlParameter("@cityID", SqlDbType.NVarChar, 50),
                new SqlParameter("@city",   SqlDbType.NVarChar, 50),
                new SqlParameter("@father", SqlDbType.NVarChar, 50)
            };

            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);
            }
        }
Example #3
0
        /// <summary>
        /// 得到一个对象实体
        /// </summary>
        public System.Model.t_city2 GetModel(int id)
        {
            StringBuilder strSql = new StringBuilder();

            strSql.Append("select id, cityID, city, father  ");
            strSql.Append("  from t_city2 ");
            strSql.Append(" where id=@id ");
            SqlParameter[] parameters =
            {
                new SqlParameter("@id", SqlDbType.Int, 4)
            };
            parameters[0].Value = id;


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

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

                return(model);
            }
            else
            {
                return(null);
            }
        }
Example #4
0
        /// <summary>
        /// 增加一条数据
        /// </summary>
        public void Add(System.Model.t_city2 model)
        {
            StringBuilder strSql = new StringBuilder();

            strSql.Append("insert into t_city2(");
            strSql.Append("id,cityID,city,father");
            strSql.Append(") values (");
            strSql.Append("@id,@cityID,@city,@father");
            strSql.Append(") ");

            SqlParameter[] parameters =
            {
                new SqlParameter("@id",     SqlDbType.Int,       4),
                new SqlParameter("@cityID", SqlDbType.NVarChar, 50),
                new SqlParameter("@city",   SqlDbType.NVarChar, 50),
                new SqlParameter("@father", SqlDbType.NVarChar, 50)
            };

            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);
        }
Example #5
0
 /// <summary>
 /// 更新一条数据
 /// </summary>
 public bool Update(System.Model.t_city2 model)
 {
     return(dal.Update(model));
 }
Example #6
0
 /// <summary>
 /// 增加一条数据
 /// </summary>
 public void  Add(System.Model.t_city2 model)
 {
     dal.Add(model);
 }