Home > DeveloperSection > Forums > how v insert data into table and display into gridview in aspx.cs file with out using wizard
Pawan kumar
Pawan kumar

Total Post:19

Points:133
Posted on    February-21-2011 7:13 AM

 ASP.Net ASP.Net 
Ratings:


 1 Reply(s)
 3006  View(s)
Rate this:


Awadhendra Tiwari

Total Post:126

Points:882
Posted on    February-22-2011 1:31 AM

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.

Don't want to miss updates? Please click the below button!

Follow MindStick