示例#1
0
        public void Save()
        {
            List <PBScrape> allData = PBScrape.GetAll();
            MySqlConnection conn    = DB.Connection();

            conn.Open();
            MySqlCommand cmd = conn.CreateCommand() as MySqlCommand;

            //Write section to get last existing id and add 1
            //cmd.Parameters.AddWithValue("@id", (int) cmd.LastInsertedId);
            cmd.Parameters.AddWithValue("@keyword", this._keyword);
            cmd.Parameters.AddWithValue("@url", this._url);
            cmd.Parameters.AddWithValue("@email", this._email);
            cmd.Parameters.AddWithValue("@phone", this._phone);
            cmd.CommandText = @"INSERT INTO pbscrape ( keyword, url, email, phone)
            VALUES ( @keyword, @url, @email, @phone);";
            MySqlDataReader rdr = cmd.ExecuteReader() as MySqlDataReader;

            cmd.ExecuteNonQuery();
            _id = (int)cmd.LastInsertedId;
            if (conn != null)
            {
                conn.Dispose();
            }
            conn.Close();
            //write get all
        }
示例#2
0
        public static List <PBScrape> GetAll()
        {
            List <PBScrape> allData = new List <PBScrape> {
            };
            MySqlConnection conn    = DB.Connection();

            conn.Open();
            MySqlCommand cmd = conn.CreateCommand() as MySqlCommand;

            cmd.CommandText = @"SELECT * FROM pbscrape;";
            MySqlDataReader rdr = cmd.ExecuteReader() as MySqlDataReader;

            while (rdr.Read())
            {
                int      instanceId      = rdr.GetInt32(0);
                string   instanceKeyword = rdr.GetString(1);
                string   instanceURL     = rdr.GetString(2);
                string   instancePhone   = rdr.GetString(3);
                string   instanceEmail   = rdr.GetString(4);
                PBScrape newInstance     = new PBScrape(instanceKeyword, instanceId, instanceURL, instanceEmail, instancePhone);
                allData.Add(newInstance);
            }
            conn.Close();
            if (conn != null)
            {
                conn.Dispose();
            }
            //write get all
            return(allData);
        }
示例#3
0
        public void Save()
        {
            List <PBScrape> allData = PBScrape.GetAll();
            MySqlConnection conn    = DB.Connection();

            conn.Open();
            MySqlCommand cmd = conn.CreateCommand() as MySqlCommand;

            cmd.CommandText = @"INSERT INTO pbscrape ( keyword, url, email, phone)
            VALUES ( @keyword, @url, @email, @phone);";
            cmd.Parameters.Add(new MySqlParameter("@keyword", this._keyword));
            cmd.Parameters.Add(new MySqlParameter("@url", this._url));
            cmd.Parameters.Add(new MySqlParameter("@email", this._email));
            cmd.Parameters.Add(new MySqlParameter("@phone", this._phone));
            cmd.ExecuteNonQuery();
            _id = (int)cmd.LastInsertedId;
            conn.Close();
            if (conn != null)
            {
                conn.Dispose();
            }
            //write get all
        }