Пример #1
0
        /// <summary>
        /// 增加一条数据
        /// </summary>
        public void Add(Light.Model.countryinfo model)
        {
            StringBuilder strSql = new StringBuilder();

            strSql.Append("insert into countryinfo(");
            strSql.Append("id,countryname,creatman,creattime,remark");
            strSql.Append(") values (");
            strSql.Append("@id,@countryname,@creatman,@creattime,@remark");
            strSql.Append(") ");

            MySqlParameter[] parameters =
            {
                new MySqlParameter("@id",          MySqlDbType.Int32,     10),
                new MySqlParameter("@countryname", MySqlDbType.VarChar,   10),
                new MySqlParameter("@creatman",    MySqlDbType.Int32,     10),
                new MySqlParameter("@creattime",   MySqlDbType.DateTime),
                new MySqlParameter("@remark",      MySqlDbType.VarChar, 200)
            };

            parameters[0].Value = model.id;
            parameters[1].Value = model.countryname;
            parameters[2].Value = model.creatman;
            parameters[3].Value = model.creattime;
            parameters[4].Value = model.remark;
            DbHelperMySQL.ExecuteSql(strSql.ToString(), parameters);
        }
Пример #2
0
        /// <summary>
        /// 得到一个对象实体
        /// </summary>
        public Light.Model.countryinfo GetModel(int id)
        {
            StringBuilder strSql = new StringBuilder();

            strSql.Append("select id, countryname, creatman, creattime, remark  ");
            strSql.Append("  from countryinfo ");
            strSql.Append(" where id=@id ");
            MySqlParameter[] parameters =
            {
                new MySqlParameter("@id", MySqlDbType.Int32, 10)
            };
            parameters[0].Value = id;


            Light.Model.countryinfo model = new Light.Model.countryinfo();
            DataSet ds = DbHelperMySQL.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.countryname = ds.Tables[0].Rows[0]["countryname"].ToString();
                if (ds.Tables[0].Rows[0]["creatman"].ToString() != "")
                {
                    model.creatman = int.Parse(ds.Tables[0].Rows[0]["creatman"].ToString());
                }
                if (ds.Tables[0].Rows[0]["creattime"].ToString() != "")
                {
                    model.creattime = DateTime.Parse(ds.Tables[0].Rows[0]["creattime"].ToString());
                }
                model.remark = ds.Tables[0].Rows[0]["remark"].ToString();

                return(model);
            }
            else
            {
                return(null);
            }
        }
Пример #3
0
        /// <summary>
        /// 更新一条数据
        /// </summary>
        public bool Update(Light.Model.countryinfo model)
        {
            StringBuilder strSql = new StringBuilder();

            strSql.Append("update countryinfo set ");

            strSql.Append(" id = @id , ");
            strSql.Append(" countryname = @countryname , ");
            strSql.Append(" creatman = @creatman , ");
            strSql.Append(" creattime = @creattime , ");
            strSql.Append(" remark = @remark  ");
            strSql.Append(" where id=@id  ");

            MySqlParameter[] parameters =
            {
                new MySqlParameter("@id",          MySqlDbType.Int32,     10),
                new MySqlParameter("@countryname", MySqlDbType.VarChar,   10),
                new MySqlParameter("@creatman",    MySqlDbType.Int32,     10),
                new MySqlParameter("@creattime",   MySqlDbType.DateTime),
                new MySqlParameter("@remark",      MySqlDbType.VarChar, 200)
            };

            parameters[0].Value = model.id;
            parameters[1].Value = model.countryname;
            parameters[2].Value = model.creatman;
            parameters[3].Value = model.creattime;
            parameters[4].Value = model.remark;
            int rows = DbHelperMySQL.ExecuteSql(strSql.ToString(), parameters);

            if (rows > 0)
            {
                return(true);
            }
            else
            {
                return(false);
            }
        }
Пример #4
0
        /// <summary>
        /// 得到一个对象实体
        /// </summary>
        public Light.Model.countryinfo GetModel(int id)
        {
            StringBuilder strSql=new StringBuilder();
            strSql.Append("select id, countryname, creatman, creattime, remark  ");
            strSql.Append("  from countryinfo ");
            strSql.Append(" where id=@id ");
                        MySqlParameter[] parameters = {
                    new MySqlParameter("@id", MySqlDbType.Int32,10)			};
            parameters[0].Value = id;

            Light.Model.countryinfo model=new Light.Model.countryinfo();
            DataSet ds=DbHelperMySQL.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.countryname= ds.Tables[0].Rows[0]["countryname"].ToString();
                                                                                                                if(ds.Tables[0].Rows[0]["creatman"].ToString()!="")
                {
                    model.creatman=int.Parse(ds.Tables[0].Rows[0]["creatman"].ToString());
                }
                                                                                                                                if(ds.Tables[0].Rows[0]["creattime"].ToString()!="")
                {
                    model.creattime=DateTime.Parse(ds.Tables[0].Rows[0]["creattime"].ToString());
                }
                                                                                                                                                model.remark= ds.Tables[0].Rows[0]["remark"].ToString();

                return model;
            }
            else
            {
                return null;
            }
        }