public List <AmphurModel> Get(int province_id) { Amphur am = new Amphur(); var amp = am.getAmphur(province_id); return(amp); }
public static List <Amphur> getAmphur(string ProvineCode) { SqlConnection conn = new SqlConnection(DataHelper.GetConnectionString()); DataSet ds = new DataSet(); List <Amphur> res = new List <Amphur>(); try { conn.Open(); StringBuilder sqlstr = new StringBuilder(); sqlstr.Append("select AMPHUR_CODE,AMPHUR_Name from AMPHUR where PROVINCE_CODE = '" + ProvineCode + "'"); SqlDataAdapter adp = new SqlDataAdapter(sqlstr.ToString(), conn); adp.SelectCommand.CommandType = CommandType.Text; adp.Fill(ds); DataTable dt = new DataTable(); Amphur model; dt = ds.Tables[0]; if (dt.Rows.Count > 0) { for (int i = 0; i < dt.Rows.Count; i++) { model = new Amphur(); model.AmphurCode = dt.Rows[i]["AMPHUR_CODE"].ToString().Trim(); model.AmphurName = dt.Rows[i]["AMPHUR_Name"].ToString().Trim(); res.Add(model); } } } catch (Exception ex) { res = null; //throw ex; } finally { conn.Close(); } return(res); }