public TanahJoin FindTanahJoin(int idTanah) { TanahJoin tanahJoin = new TanahJoin(); JenisTanah jenisTanah = new JenisTanah(); Lokasi lokasi = new Lokasi(); using (MySqlConnection conn = GetConnection()) { conn.Open(); MySqlCommand cmd = new MySqlCommand("SELECT * FROM tanah INNER JOIN jenis_tanah ON jenis_tanah.id_jenistanah = tanah.id_jenistanah INNER JOIN lokasi ON lokasi.id_lokasi = tanah.id_lokasi WHERE id_tanah = '" + idTanah + "'", conn); using (MySqlDataReader reader = cmd.ExecuteReader()) { while (reader.Read()) { tanahJoin.IdTanah = reader.GetInt32("id_tanah"); tanahJoin.Suhu = reader.GetInt32("suhu"); tanahJoin.LuasTanah = reader.GetInt32("luas_tanah"); jenisTanah.IdJenisTanah = reader.GetInt32("id_jenistanah"); jenisTanah.NamaJenisTanah = reader.GetString("nama_jenistanah"); lokasi.IdLokasi = reader.GetInt32("id_lokasi"); lokasi.Kecamatan = reader.GetString("kecamatan"); lokasi.Kabupaten = reader.GetString("kabupaten"); lokasi.Provinsi = reader.GetString("provinsi"); lokasi.KodePos = reader.GetInt32("kode_pos"); lokasi.Latitude = reader.GetDecimal("latitude"); lokasi.Longitude = reader.GetDecimal("longtitude"); tanahJoin.JenisTanah = jenisTanah; tanahJoin.Lokasi = lokasi; } } } return(tanahJoin); }
public JenisTanah FindJenisTanah(int idJenisTanah) { JenisTanah jenisTanah = new JenisTanah(); using (MySqlConnection conn = GetConnection()) { conn.Open(); MySqlCommand cmd = new MySqlCommand("SELECT * FROM jenis_tanah WHERE id_jenistanah = ('" + idJenisTanah + "')", conn); using (MySqlDataReader reader = cmd.ExecuteReader()) { while (reader.Read()) { jenisTanah.IdJenisTanah = reader.GetInt32("id_jenistanah"); jenisTanah.NamaJenisTanah = reader.GetString("nama_jenistanah"); } } } return(jenisTanah); }