示例#1
0
        public static DBPrepaidCable GetDataByCode(string code)
        {
            DBPrepaidCable data = null;

            MySqlConnection con = DBConnection.ConnectDatabase();

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

                if (reader.HasRows)
                {
                    reader.Read();
                    data             = new DBPrepaidCable();
                    data.Id          = reader.GetInt32(0);
                    data.Code        = reader.GetString(1);
                    data.Description = reader.GetString(2);
                    data.Gateway     = reader.GetString(3);
                }

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

            return(data);
        }
示例#2
0
        public static List <DBPrepaidCable> GetData()
        {
            List <DBPrepaidCable> data = new List <DBPrepaidCable>();

            MySqlConnection con = DBConnection.ConnectDatabase();

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

                if (reader.HasRows)
                {
                    while (reader.Read())
                    {
                        DBPrepaidCable rawData = new DBPrepaidCable();
                        rawData.Id          = reader.GetInt32(0);
                        rawData.Code        = reader.GetString(1);
                        rawData.Description = reader.GetString(2);
                        rawData.Gateway     = reader.GetString(3);

                        data.Add(rawData);
                    }
                }

                reader.Close();
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
            finally
            {
                con.Close();
            }

            return(data);
        }