Example : How to store multiple records into datagrid view of Asp.net/C# from Sql Server Database.
protected void Page_Load(object sender, EventArgs e)
        {
            string cs = "data source =.; database= SITEDB; integrated security=SSPI";
            //string cs = @"Data Source =.; Initial Catalog=SITEDB;";
            con = new SqlConnection(cs);
            Response.Write("Data Base Connected...");


            try
            {
                con.Open();
                SqlCommand cmd = new SqlCommand("select Slno, Name as [Customer Name], Email+', '+Pass as [Mail & Password], Dob as [Date of Birth], Gen as Gender, Matric+', '+ Inter+', '+ Grad+', '+PGrad as Qulification, Address+','+city+','+pin as Address from Traildb", con);
                SqlDataReader dr = cmd.ExecuteReader();
                if (dr.HasRows == true)
                {
                    GridView1.DataSource = dr;
                    GridView1.DataBind();
                }
            }
            catch (SqlException ex)
            {
                Response.Write(ex.Message);
            }
            finally
            {
                con.Close();
            }  
        }
Example : How to store multiple records into datagrid view from html controls or text boxes in Asp.net/C#.

Loading

Categories: ASP .Net

0 Comments

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.