Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3932342
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 19, 20262026-05-19T23:26:51+00:00 2026-05-19T23:26:51+00:00

Edit: I solved my problem but if you have anything to add please do.

  • 0

Edit: I solved my problem but if you have anything to add please do. Thanks

Note: I did not create the DB it was created by WordPress hosted on GoDaddy with my site

I have a MySql Database called “wordpress” (for clarity). I want to be able to grab the most recent post from my blog and show it on the landing page for my url.
So my thought is this: connect to the MySql DB, run a query to grab the most recent post, display the post.

I built a class to handle the connection and process the request:

public class DAL
    {
        private string connectionString = "DRIVER={MySQL ODBC 3.51 Driver}; SERVER=[server here]; PORT=[port]; DATABASE=wordpress; 
            USER=[user name here]; PASSWORD=[password here];";
        private OdbcConnection blogConnection;

        public DAL()
        {
            blogConnection = new OdbcConnection(connectionString);
        }

        public String[] GetRecentPost()
        {
            string queryString = "SELECT * FROM RecentPost";
            String[] recentPost = new String[3];

            //ODBC
            blogConnection.Open();

            OdbcCommand MySqlDB = new OdbcCommand(queryString, blogConnection);
            OdbcDataReader reader = MySqlDB.ExecuteReader();

            while (reader.NextResult())
            {
                recentPost[0] = reader.GetString(0);
                recentPost[1] = reader.GetString(1);
            }
            recentPost[2] = reader.HasRows.ToString();
            blogConnection.Close();

            return recentPost;
        }
    }

In the queryString above RecentPost is a view I created to simplify the queryString since the query was a bit long.
I already know the view works. I tested it by opening phpMyAdmin from within the GoDaddy Hosting Center and executed the query above and I got the correct result, so I don’t think the query/view is wrong.

The code-behind for the landing page:

protected void Page_Load(object sender, EventArgs e)
        {
            DAL dataAccess = new DAL();

            String[] recentPost = dataAccess.GetRecentPost();

            Title.Text = recentPost[0];
            Post.Text = recentPost[1];
            Extra.Text = recentPost[2];
        }

So when my page loads the Title and Post texts are empty and Extra.Text is False (which from the DAL is the value from reader.HasRows).
So my guess is that its connecting fine and running the query but maybe on the wrong database? I don’t know.

I also tried to debug but then my code throws an error about trying to connect to database.

So my questions are: Do you see anything wrong with the connection string?

If not do you see anything else than would cause a connection to be esablished, a query to run, no exceptions thrown but no results returned?

Any one with experience trying to grab data from thier own wordpress blog?

Thanks for the help – this one has been driving me crazy.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-19T23:26:52+00:00Added an answer on May 19, 2026 at 11:26 pm

    I don’t know why my original code wasn’t working but I solved my issue. For anyone else having this issue here is how I changed my code (in the GetRecentPost method) and solved my problem:

    DataSet ds = new DataSet();
    
    //ODBC
    blogConnection.Open();
    
    OdbcDataAdapter MySqlDB = new OdbcDataAdapter(queryString, blogConnection);
    MySqlDB.Fill(ds);
    return ds.Tables[0];
    

    So instead of an array of strings I used a DataSet. Instead of using the OdbcDataReader I used an OdbcDataAdapter and populated the DataSet with the .Fill() method from OdbcDataAdapter I then returned the first table from the DataSet to my Page_Load method.

    Here is my new Page_Load():

    DataTable table = dataAccess.GetRecentPost();
    
    if (table.Rows.Count > 0)
    {
        Title.Text = table.Rows[0]["title"].ToString();
        Post.Text = table.Rows[0]["content"].ToString();
    }
    else
        Extra.Text = table.Rows.Count.ToString(); \\if nothing was returned ouput the 0 just to be sure
    

    Hope this helps anyone else with this issue

    And thanks for anyone who took the time to look

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

[SOLVED] dont ask me how i have no idea, i didnt change anything but
Edit: I have solved this by myself. See my answer below I have set
EDIT: Solved, (at least for the explorer) the problem was it keeps the old
The question is in the title... I searched but couldn't find anything. Edit: I
Solved the problem see the bottom of my post. So I have a simple
Edit : Solved, there was a trigger with a loop on the table (read
edit #2: Question solved halfways. Look below As a follow-up question, does anyone know
EDIT: Learned that Webmethods actually uses NLST, not LIST, if that matters Our business
I have a problem that I don't know how to solve. I have have
I have one thread that inserts into the queueStream (not shown here) and FlowController

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.