public object Select(int num, int Province_ID, int Amphur_ID) { object result = null; CStatementList cstate = new CStatementList(_SQLConnection.CSQLConnection); try { try { CSQLParameterList plist = new CSQLParameterList(); plist.Add("@num", DbType.Int32, num, ParameterDirection.Input); plist.Add("@Province_ID", DbType.Int32, Province_ID, ParameterDirection.Input); plist.Add("@Amphur_ID", DbType.Int32, Amphur_ID, ParameterDirection.Input); CSQLDataAdepterList adlist = new CSQLDataAdepterList(); CSQLStatementValue csvUser = new CSQLStatementValue(this._statement, plist, NoomLibrary.StatementType.Select); adlist.Add(csvUser); cstate.Open(); result = cstate.Execute(adlist); DataTable dt = (DataTable)result; foreach (DataRow item in dt.Rows) { int id = int.Parse(item["DISTRICT_ID"].ToString()); _District _c = new _District(); _c.DISTRICT_ID = id; _c.DISTRICT_NAME = item["DISTRICT_NAME"].ToString(); this.Add(id, _c); } cstate.Commit(); } catch (SqlException) { cstate.Rollback(); throw; } finally { cstate.Close(); } } catch (Exception) { throw; } return(result); }
public static List <_District> GetDistricts() { MySqlConnection scon = new MySqlConnection(WebConfigurationManager.ConnectionStrings["LocalMySqlServer"].ConnectionString); MySqlCommand scmd = new MySqlCommand(); scon.Open(); scmd.Connection = scon; List <_District> distList = new List <_District>(); try { scmd.CommandText = "SELECT * from districts"; scmd.Prepare(); MySqlDataReader sdr = scmd.ExecuteReader(); if (sdr.HasRows) { while (sdr.Read()) { _District dist = new _District(); dist.DID = Convert.ToInt32(sdr.GetString(0)); dist.DCODE = sdr.GetString(1); dist.DNAME = sdr.GetString(2); distList.Add(dist); } } sdr.Close(); sdr.Dispose(); } catch (Exception ee) { } finally { if (scmd != null) { scmd.Dispose(); } if (scon.State == ConnectionState.Open) { scon.Dispose(); scon.Close(); } } return(distList); }