Ejemplo n.º 1
0
        public static DBCities GetDataByName(string idx)
        {
            DBCities data = null;

            MySqlConnection con = DBConnection.ConnectLocalAddressDatabase();

            try
            {
                MySqlCommand    cmd    = new MySqlCommand("SELECT * FROM " + tablename + " WHERE city='" + idx + "'", con);
                MySqlDataReader reader = cmd.ExecuteReader();

                if (reader.HasRows)
                {
                    reader.Read();
                    data        = new DBCities();
                    data.ID     = reader.GetInt32(0);
                    data.NAME   = reader.GetString(1);
                    data.PROVID = reader.GetInt32(2);
                }

                reader.Close();
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
            }
            finally
            {
                con.Close();
            }

            return(data);
        }
Ejemplo n.º 2
0
        public static List <DBCities> GetDataByProvice(int idx)
        {
            List <DBCities> data = new List <DBCities>();

            MySqlConnection con = DBConnection.ConnectLocalAddressDatabase();

            try
            {
                MySqlCommand    cmd    = new MySqlCommand("SELECT * FROM " + tablename + " WHERE province_id=" + idx, con);
                MySqlDataReader reader = cmd.ExecuteReader();

                if (reader.HasRows)
                {
                    while (reader.Read())
                    {
                        DBCities rawData = new DBCities();
                        rawData.ID     = reader.GetInt32(0);
                        rawData.NAME   = reader.GetString(1);
                        rawData.PROVID = reader.GetInt32(2);
                        data.Add(rawData);
                    }
                }

                reader.Close();
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
            }
            finally
            {
                con.Close();
            }

            return(data);
        }