Click here to Skip to main content
15,881,248 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
how we dispaly data in grid view from sql server
Posted
Comments
frostcox 20-Mar-13 6:22am    
You need to load your sql data in to a datatable and set the datasource of your gridview to your datatable.

hi!!!

C#
on button click event
                 {
                  con.Open();//connection open
                  SqlCommand cmd = new SqlCommand("Select * from tablename", con);

                 // SqlCommand cmd = new SqlCommand(hidSelectedText.Value, con);
                  SqlDataAdapter da = new SqlDataAdapter(cmd);
                  DataTable dt = new DataTable();
                  da.Fill(dt);
                  GridView1.DataSource = dt;
                  GridView1.DataBind();
                  con.Close();
                  }
 
Share this answer
 
v2
Please show the Code that you have tried.

You need to code for that operation.You need to run your Sql query.

String Command="Select * from table(Name of table)";
SqlDataadapter da=new SqlDataadapter(Command,Con);//(Connection Object)
Dataset ds=new Dataset();
da.fill(ds);
Gridview.DataSource=ds.Tables[0];

Thanks
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900