public static bool Insert(Case mycase) { string sql = @"insert into t_case ( country, hotel, image ) values ( ?country, ?hotel, ?image )"; MySqlParameter[] parms = new MySqlParameter[] { new MySqlParameter("?country", MySqlDbType.VarChar), new MySqlParameter("?hotel", MySqlDbType.VarChar), new MySqlParameter("?image", MySqlDbType.VarChar) }; parms[0].Value = mycase.country; parms[1].Value = mycase.hotel; parms[2].Value = mycase.image; int result = DbHelper.ExecuteNonQuery(sql, parms); return result > 0; }
protected void btnAdd_Click(object sender, EventArgs e) { Case mycase = new Case(); mycase.country = this.txtCountry.Text; mycase.hotel = this.txtHotel.Text; string fckStr = CKEditor1.Text; MatchCollection matchs = Regex.Matches(fckStr, @"<img[^src]*src=""[^http\://]*(?<src>[^""]*?)""", RegexOptions.IgnoreCase); foreach(Match m in matchs) { mycase.image = m.Groups["src"].Value.ToString(); break; } // if (string.IsNullOrEmpty(my)) }
public static Case GetItem(int id) { string sql = "select * from t_case where id=?id"; MySqlParameter[] parms = new MySqlParameter[] { new MySqlParameter("?id", MySqlDbType.Int32) }; parms[0].Value = id; MySqlDataReader reader = DbHelper.ExecuteDataReader(sql, parms); Case mycase = new Case(); if (reader.HasRows) { if(reader.Read()) { mycase = FillDataRecord(reader); } } reader.Close(); return mycase; }
public static bool Update(Case mycase) { return CaseService.Update(mycase); }
public static bool Insert(Case mycase) { return CaseService.Insert(mycase); }
public static bool Update(Case mycase) { string sql = "update t_case set country=?country, hotel=?hotel, image=?image where id=?id"; MySqlParameter[] parms = new MySqlParameter[] { new MySqlParameter("?country", MySqlDbType.VarChar), new MySqlParameter("?hotel", MySqlDbType.VarChar), new MySqlParameter("?image", MySqlDbType.VarChar), new MySqlParameter("?id", MySqlDbType.Int32) }; parms[0].Value = mycase.country; parms[1].Value = mycase.hotel; parms[2].Value = mycase.image; parms[3].Value = mycase.id; int result = DbHelper.ExecuteNonQuery(sql, parms); return result > 0; }
private static Case FillDataRecord(System.Data.IDataRecord myDataRecord) { Case mycase = new Case(); mycase.id = myDataRecord.GetInt16(myDataRecord.GetOrdinal("id")); mycase.country = myDataRecord.GetString(myDataRecord.GetOrdinal("country")); mycase.hotel = myDataRecord.GetString(myDataRecord.GetOrdinal("hotel")); mycase.image = myDataRecord.GetString(myDataRecord.GetOrdinal("image")); return mycase; }