/// <summary> /// 增加一条数据 /// </summary> public void Add(Light.Model.cityinfo model) { StringBuilder strSql = new StringBuilder(); strSql.Append("insert into cityinfo("); strSql.Append("id,regionid,cityname,creatman,creattime,remark"); strSql.Append(") values ("); strSql.Append("@id,@regionid,@cityname,@creatman,@creattime,@remark"); strSql.Append(") "); MySqlParameter[] parameters = { new MySqlParameter("@id", MySqlDbType.Int32, 10), new MySqlParameter("@regionid", MySqlDbType.Int32, 10), new MySqlParameter("@cityname", 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.regionid; parameters[2].Value = model.cityname; parameters[3].Value = model.creatman; parameters[4].Value = model.creattime; parameters[5].Value = model.remark; DbHelperMySQL.ExecuteSql(strSql.ToString(), parameters); }
/// <summary> /// 得到一个对象实体 /// </summary> public Light.Model.cityinfo GetModel(int id) { StringBuilder strSql = new StringBuilder(); strSql.Append("select id, regionid, cityname, creatman, creattime, remark "); strSql.Append(" from cityinfo "); strSql.Append(" where id=@id "); MySqlParameter[] parameters = { new MySqlParameter("@id", MySqlDbType.Int32, 10) }; parameters[0].Value = id; Light.Model.cityinfo model = new Light.Model.cityinfo(); 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()); } if (ds.Tables[0].Rows[0]["regionid"].ToString() != "") { model.regionid = int.Parse(ds.Tables[0].Rows[0]["regionid"].ToString()); } model.cityname = ds.Tables[0].Rows[0]["cityname"].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); } }
/// <summary> /// 更新一条数据 /// </summary> public bool Update(Light.Model.cityinfo model) { StringBuilder strSql = new StringBuilder(); strSql.Append("update cityinfo set "); strSql.Append(" id = @id , "); strSql.Append(" regionid = @regionid , "); strSql.Append(" cityname = @cityname , "); 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("@regionid", MySqlDbType.Int32, 10), new MySqlParameter("@cityname", 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.regionid; parameters[2].Value = model.cityname; parameters[3].Value = model.creatman; parameters[4].Value = model.creattime; parameters[5].Value = model.remark; int rows = DbHelperMySQL.ExecuteSql(strSql.ToString(), parameters); if (rows > 0) { return(true); } else { return(false); } }
/// <summary> /// 得到一个对象实体 /// </summary> public Light.Model.cityinfo GetModel(int id) { StringBuilder strSql=new StringBuilder(); strSql.Append("select id, regionid, cityname, creatman, creattime, remark "); strSql.Append(" from cityinfo "); strSql.Append(" where id=@id "); MySqlParameter[] parameters = { new MySqlParameter("@id", MySqlDbType.Int32,10) }; parameters[0].Value = id; Light.Model.cityinfo model=new Light.Model.cityinfo(); 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()); } if(ds.Tables[0].Rows[0]["regionid"].ToString()!="") { model.regionid=int.Parse(ds.Tables[0].Rows[0]["regionid"].ToString()); } model.cityname= ds.Tables[0].Rows[0]["cityname"].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; } }