locked
How to display the result of this code into a table ? RRS feed

  • Question

  • User-2071692902 posted

    How to display the result of this code into a table ?

    Hi there,
    I have written this code and now I want to put show its result in a table .
    The code is
    $sql='SELECT id , fname , reg_date ,
    CONCAT("Registerd ", DATEDIFF(CURDATE(), reg_date), " Days Age.")
    AS RegisteredSence 
    FROM users;
    Any idea?
    Sunday, April 5, 2020 6:04 AM

Answers

  • User288213138 posted

    Hi Omamxp45-1,

    $sql='SELECT id , fname , reg_date ,
    CONCAT("Registerd ", DATEDIFF(CURDATE(), reg_date), " Days Age.")
    AS RegisteredSence 
    FROM users;

    Can you tell me what this is?  sql statement? But there is no $ symbol in TSql.

    If you want to display the results of a query in a table, I recommend Ado.net.

     <asp:GridView ID="GridView1" runat="server"></asp:GridView>
    string constr = ConfigurationManager.ConnectionStrings["constr"].ConnectionString;
                string query = "";
                using (SqlConnection con = new SqlConnection(constr))
                {
                    using (SqlDataAdapter sda = new SqlDataAdapter(query, con))
                    {
                        using (DataTable dt = new DataTable())
                        {
                            sda.Fill(dt);
                            GridView1.DataSource = dt;
                            GridView1.DataBind();
                        }
                    }
                }

    If I misunderstand your requirement, please post more details information about your requirement.

    Best regards,

    Sam

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Monday, April 6, 2020 8:57 AM