public District Find(string name) { string query = "SELECT * FROM tbl_districts WHERE name='" + name + "';"; DbSqlConnection = new SqlConnection(ConnectionString); DbSqlConnection.Open(); DbSqlCommand = new SqlCommand(query, DbSqlConnection); DbSqlDataReader = DbSqlCommand.ExecuteReader(); District aDistrict = new District(); DbSqlDataReader.Read(); aDistrict.Id = Convert.ToInt32(DbSqlDataReader["id"]); aDistrict.Name = DbSqlDataReader["name"].ToString(); DbSqlDataReader.Close(); DbSqlConnection.Close(); return(aDistrict); }
public List <District> GetDistricts() { List <District> districtList = new List <District>(); string query = "SELECT * FROM tbl_districts"; DbSqlConnection = new SqlConnection(ConnectionString); DbSqlConnection.Open(); DbSqlCommand = new SqlCommand(query, DbSqlConnection); DbSqlDataReader = DbSqlCommand.ExecuteReader(); while (DbSqlDataReader.Read()) { District aDistrict = new District(); aDistrict.Id = Convert.ToInt32(DbSqlDataReader["id"]); aDistrict.Name = DbSqlDataReader["name"].ToString(); districtList.Add(aDistrict); } DbSqlDataReader.Close(); DbSqlConnection.Close(); return(districtList); }
public List <Thana> GetThanas(int districtId) { List <Thana> thanaList = new List <Thana>(); string query = "SELECT * FROM tbl_thanas WHERE district_id=" + districtId + " ORDER BY name;"; DbSqlConnection = new SqlConnection(ConnectionString); DbSqlConnection.Open(); DbSqlCommand = new SqlCommand(query, DbSqlConnection); DbSqlDataReader = DbSqlCommand.ExecuteReader(); while (DbSqlDataReader.Read()) { Thana aThana = new Thana(); aThana.Id = Convert.ToInt32(DbSqlDataReader["id"]); aThana.Name = DbSqlDataReader["name"].ToString(); aThana.DistrictId = Convert.ToInt32(DbSqlDataReader["district_id"]); thanaList.Add(aThana); } DbSqlDataReader.Close(); DbSqlConnection.Close(); return(thanaList); }