public IHttpActionResult getAmphurData(string province) { List <zipcodedata> result = new List <zipcodedata>(); DBConnector.DBConnector conn = new DBConnector.DBConnector(); string SQLString; if (conn.OpenConnection()) { MySqlCommand qExe = new MySqlCommand(); qExe.Connection = conn.connection; SQLString = @"select distinct province, amphur from zip_data where province = '" + province + @"' order by amphur"; qExe.CommandText = SQLString; MySqlDataReader dataReader = qExe.ExecuteReader(); while (dataReader.Read()) { zipcodedata detail = new zipcodedata(); detail.province = dataReader["province"].ToString(); detail.amphur = dataReader["amphur"].ToString(); detail.tambon = ""; detail.zipcode = ""; result.Add(detail); } return(Json(result)); } else { return(BadRequest("Database connect fail!")); } }
public IHttpActionResult getZipCodeData(string zipcode) { zipcodedata result = new zipcodedata(); DBConnector.DBConnector conn = new DBConnector.DBConnector(); string SQLString; if (conn.OpenConnection()) { if (!string.IsNullOrEmpty(zipcode)) { MySqlCommand qExe = new MySqlCommand(); qExe.Connection = conn.connection; SQLString = @"select * from zip_data where zipcode = '" + zipcode + "'"; qExe.CommandText = SQLString; MySqlDataReader dataReader = qExe.ExecuteReader(); while (dataReader.Read()) { result.province = dataReader["province"].ToString(); result.amphur = dataReader["amphur"].ToString(); result.tambon = dataReader["tambon"].ToString(); result.zipcode = dataReader["zipcode"].ToString(); } } return(Json(result)); } else { return(BadRequest("Database connect fail!")); } }