예제 #1
0
        /// <summary>
        /// 导入行数据插入到数据库
        /// </summary>
        /// <param name="model"></param>
        /// <param name="transaction"></param>
        private void EmportRowInsert(ModCityArea model, SqlTransaction transaction)
        {
            //insert语句
            string sql = @"insert into cityarea(areaprovince, areacity, areapostcode, created, created_time) 
                                values(@areaprovince, @areacity, @areapostcode, @created, getdate())";

            //参数数组
            SqlParameter[] _params = new SqlParameter[] {
                new SqlParameter("@areaprovince", model.AreaProvince),
                new SqlParameter("@areacity", model.AreaCity),
                new SqlParameter("@areapostcode", model.AreaPostcode),
                new SqlParameter("@created", model.Created)
            };

            //执行插入操作
            SQLHelper.ExecuteNonQuery(transaction, CommandType.Text, sql, _params);
        }
예제 #2
0
        /// <summary>
        /// 导入行数据更新到数据库
        /// </summary>
        /// <param name="model"></param>
        /// <param name="transaction"></param>
        private void EmportRowUpdate(ModCityArea model, SqlTransaction transaction)
        {
            //update语句
            string sql = @"update cityarea set areaprovince = @areaprovince, areacity = @areacity, areapostcode = @areapostcode,
                                    updated = @updated, updated_time = getdate() where areaid = @areaid";

            //参数数组
            SqlParameter[] _params = new SqlParameter[] {
                new SqlParameter("@areaprovince", model.AreaProvince),
                new SqlParameter("@areacity", model.AreaCity),
                new SqlParameter("@areapostcode", model.AreaPostcode),
                new SqlParameter("@updated", model.Updated),
                new SqlParameter("@areaid", model.AreaID)
            };

            //执行更新操作
            SQLHelper.ExecuteNonQuery(transaction, CommandType.Text, sql, _params);
        }
예제 #3
0
        /// <summary>
        /// 判断数据库中省份+城市是否已存在
        /// </summary>
        /// <param name="model"></param>
        /// <param name="transaction"></param>
        /// <returns></returns>
        private int EmportRowIsRepeat(ModCityArea model, SqlTransaction transaction)
        {
            //不为空时, 城市 数据库是否已存在
            string strSql = string.Format("select top 1 areaid from cityarea where areaprovince = '{0}' and areacity = '{1}' order by areaid",
                                          model.AreaProvince.Trim(), model.AreaCity.Trim());

            object result = SQLHelper.ExecuteScalar(transaction, CommandType.Text, strSql, null);

            //返回对应记录ID
            if (null == result)
            {
                return(0);
            }
            else
            {
                return(Convert.ToInt32(result));
            }
        }