HOW V INSERT DATA INTO TABLE AND DISPLAY INTO GRIDVIEW IN ASPX.CS FILE WITH OUT USING WIZARD

Pawan kumar

Total Post:19

Points:133
Posted by  Pawan kumar
 3257  View(s)
Ratings:
Rate this:
  1. Awadhendra Tiwari

    Post:126

    Points:882
    Re: how v insert data into table and display into gridview in aspx.cs file with out using wizard

    I can not understand your question correctly. How do you entered data in table. By using sql management window or any other. Well Here I can show you a method to insert data in table by using sql command management window than programmatically display that data in grid view.

    Write down following commands to insert data in sql management window

    Insert into Student values(‘S0001’,’Jon’,’Lues’,21,’New Verginia’)

    Method to display data in grid view

    Drag-Drop Grid view control on aspx page at design view then double click the page and at the load event of page write down following code

    public void loadData()

    {

            SqlConnection con = new SqlConnection();

            con.ConnectionString = "Pass connection string of your sql server.";

            SqlCommand cmd = new SqlCommand("select * from Student", con);

            con.Open();

            SqlDataReader dr = cmd.ExecuteReader();

            DataTable dt = new DataTable();

            dt.Load(dr);

            GridView1.DataSource = dt.DefaultView;

            GridView1.DataBind();

            con.Close();

    }

    One thing important to use SqlConnection object and DataTable object please use two namespace first one is using System.Data and second one is System.Data.SqlClient.

Answer

NEWSLETTER

Enter your email address here always to be updated. We promise not to spam!