Wednesday, April 15, 2015

Display data in aspx page in asp.net

SqlConnection con = new SqlConnection(@"your connection string");
    SqlCommand cmd;
    SqlDataReader rd;
    protected void Page_Load(object sender, EventArgs e)
    {

    }
    protected void Button1_Click(object sender, EventArgs e)
    {
        cmd = new SqlCommand("select * from std", con);
        con.Open();
        rd = cmd.ExecuteReader();
        if (rd.HasRows)
        {
            while (rd.Read())
            {
                Response.Write(rd["fieldname1"].ToString() + "  " + rd["fieldname2"].ToString() + "  " + rd["lname"].ToString()+"<br>");
            }
            con.Close();
        }

    }
    

No comments:

Post a Comment