Hi,
i am beginner for Dot Net and i don't know how to show a data from sql server in gridview.
Please give me solutions .
Thanks & Regards
Know the answer? Post it. Somebody with the same question will find it here.
Answer a question in the forums and earn +20 SHARP for every answer.
See unanswered questions
DevSocialUpcoming · 3rd editionAI Agents ConferenceDec 1–3, 2026Live onlineFree to attend5days leftRegister
Rajeesh MenothRank #118 · 18.4K reputationPosted Jun 30, 2015, 10:45 PM EDT
RakeshRank #397 · 6.3K reputationPosted Jun 30, 2015, 10:48 PM EDT
Pankaj Kumar ChoudharyRank #80 · 24.4K reputationPosted Jul 1, 2015, 1:54 AM EDT
how to get data from sql database to gridview by coding
C# DataGridView Binding - SQL S
how to display data from sql server in gridview - CodeProject
erver dataset
Munesh SharmaRank #174 · 13.9K reputationPosted Jul 1, 2015, 2:30 AM EDT
Narasimha Reddy ChennupalliRank #1,163 · 1.6K reputationPosted Jul 4, 2015, 10:04 AM EDT
String strConnection="";// connection string here
SqlConnection con=new SqlConnection(strConnection);
SqlCommand cmd=new SqlCommand("select * from EmpTable", con);
SqlDataAdapter da=new SqlDataAdapter(cmd);
Dataset ds=new Dataset ();
con.Open();
da.fill(ds);
Gridview1.DataSource=ds;
Gridview1.DataBound;
con.Close();
Rahul PrajapatRank #1,209 · 1.5K reputationPosted Jul 4, 2015, 3:49 PM EDT
Dataset ds=new Dataset ();
da.fill(ds);
Gridview1.DataSource=ds;
Gridview1.DataBind();
con.Close();
Narasimha Reddy ChennupalliRank #1,163 · 1.6K reputationPosted Jul 4, 2015, 9:09 PM EDT
Small correction on your code snippet
SqlCommand cmd=new SqlCommand("select * from table_Name", con);
SqlDataAdapter da=new SqlDataAdapter(cmd,con);//Wrong
// here no need to give connection
SqlDataAdapter da=new SqlDataAdapter(cmd);// correct
// bcz you already mention the connection in cmd(object of Sql Command).