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

            MySqlConnection con = DBConnection.ConnectLocalAddressDatabase();

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

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

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

            return(data);
        }
Ejemplo n.º 2
0
        public static List <DBProvinces> GetData()
        {
            List <DBProvinces> data = new List <DBProvinces>();

            MySqlConnection con = DBConnection.ConnectLocalAddressDatabase();

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

                if (reader.HasRows)
                {
                    while (reader.Read())
                    {
                        DBProvinces rawData = new DBProvinces();
                        rawData.ID   = reader.GetInt32(0);
                        rawData.NAME = reader.GetString(1);

                        data.Add(rawData);
                    }
                }

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

            return(data);
        }