Example #1
0
        public Webpage FindWebPage(int id)
        {
            MySqlConnection sqlCon      = new MySqlConnection(ConnectionString);
            Webpage         result_page = new Webpage();

            try
            {
                string query = "select * from PAGES where page_id = " + id;

                sqlCon.Open();
                MySqlCommand    cmd       = new MySqlCommand(query, sqlCon);
                MySqlDataReader resultset = cmd.ExecuteReader();

                List <Webpage> page = new List <Webpage>();

                while (resultset.Read())
                {
                    Webpage currentpage = new Webpage();
                    for (int i = 0; i < resultset.FieldCount; i++)
                    {
                        string key   = resultset.GetName(i);
                        string value = resultset.GetString(i);
                        Debug.WriteLine("Attempting to transfer " + key + " data of " + value);
                        switch (key)
                        {
                        case "page_title":
                            currentpage.set_W_title(value);
                            break;

                        case "page_body":
                            currentpage.set_W_body(value);
                            break;

                        case "publish_author":
                            currentpage.set_W_author(value);
                            break;

                        case "publish_state":
                            currentpage.set_W_publish_state(value);
                            break;

                        case "publish_date":
                            currentpage.set_W_publish_date(value);
                            break;
                        }
                    }
                    page.Add(currentpage);
                }

                result_page = page[0];
            }
            catch (Exception ex)
            {
                Debug.WriteLine("Check the findWebpage()");
                Debug.WriteLine(ex.ToString());
            }

            sqlCon.Close();
            Debug.WriteLine("Database Connection Terminated.");

            return(result_page);
        }