none
How to get today posts in MySQL? RRS feed

  • Question

  • Hi Friends,

    Good Day,

    Here is the requirement, if someone posts in a website and i need only today post's to select.

    How can i do it by using MySQL Datebase.

    Thanks


    Thanks&Regards
    Thanks&Regards
    • Moved by Bob Beauchemin Tuesday, January 10, 2012 7:32 PM Moved to a (possibly) more relvent forum, if this post is referencing the .NET MySQL provider. If not, you can obtain information on MySQL forums (From:.NET Framework inside SQL Server)
    Tuesday, January 10, 2012 7:39 AM

Answers

  • Hi manilubna,

    Welcome to MSDN Forum.

    Based on the post, I think there's a post table which stored the post information in your database. In order to connect to MySQL database, you need to download MySQL provider first, here's a download site: ADO.NET Data Provider. After that, add reference of the MySQL.Data.dll and import the namespace by using statement.

    You can write the code as below

    using (MySqlConnection con = new MySqlConnection("your connection string"))
                {
                    string sql = "select * from post where postDate=@postDate";
                    MySqlCommand cmd = new MySqlCommand();
                    cmd.Connection = con;
                    cmd.CommandText = sql;
                    cmd.Parameters.Add("@postDate", DateTime.Now.Date);
                    MySqlDataAdapter adapter = new MySqlDataAdapter(cmd);
                    DataSet ds = new DataSet();
                    adapter.Fill(ds);
                }
    


    Best Regards


    Allen Li [MSFT]
    MSDN Community Support | Feedback to us
    Thursday, January 12, 2012 3:25 AM
    Moderator
  • Hi manilubna,

    Please privde the BAL and DAL file, this is, so I can help you to write the code.

    Best Regards


    Allen Li [MSFT]
    MSDN Community Support | Feedback to us
    • Marked as answer by manilubna Wednesday, March 14, 2012 7:43 AM
    Friday, January 13, 2012 2:40 AM
    Moderator

All replies

  • Hi manilubna,

    Welcome to MSDN Forum.

    Based on the post, I think there's a post table which stored the post information in your database. In order to connect to MySQL database, you need to download MySQL provider first, here's a download site: ADO.NET Data Provider. After that, add reference of the MySQL.Data.dll and import the namespace by using statement.

    You can write the code as below

    using (MySqlConnection con = new MySqlConnection("your connection string"))
                {
                    string sql = "select * from post where postDate=@postDate";
                    MySqlCommand cmd = new MySqlCommand();
                    cmd.Connection = con;
                    cmd.CommandText = sql;
                    cmd.Parameters.Add("@postDate", DateTime.Now.Date);
                    MySqlDataAdapter adapter = new MySqlDataAdapter(cmd);
                    DataSet ds = new DataSet();
                    adapter.Fill(ds);
                }
    


    Best Regards


    Allen Li [MSFT]
    MSDN Community Support | Feedback to us
    Thursday, January 12, 2012 3:25 AM
    Moderator
  • Hello Allen,

    Great Day.

    Thanks for your support, can you provide me this by using BAL and DAL.

    Please make a move.

    Thanks

    ManiLubna


    Thanks&Regards
    Thursday, January 12, 2012 9:24 AM
  • Hi manilubna,

    Please privde the BAL and DAL file, this is, so I can help you to write the code.

    Best Regards


    Allen Li [MSFT]
    MSDN Community Support | Feedback to us
    • Marked as answer by manilubna Wednesday, March 14, 2012 7:43 AM
    Friday, January 13, 2012 2:40 AM
    Moderator