Hi friends,
I have created a employeetable in sqlserver-2008,now my task is to retrieve that table data and display in my asp.net webpage in a gridview control please tell me iam a fresher i tried a lot but struck somewhere
Loading
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 attend4days leftRegister
Jiteendra SampathiraoRank #585 · 4.1K reputationPosted Jul 19, 2011, 4:56 AM EDT
There is so many ways to retrieve the data from Sql server and store it in GridView...
First way:
Ado.Net provides default datasources like Sqldatasource, XMLDatasource etc.
Refer this link to know more about Data sources: click Here
Accessing Data with the DataSource Controls
Using data sources and storing values in gridview is easy approach.
Second way:
Manually you can do that: refer this Link
you can found more articles regarding this topic....
i hope it help you....
Satyapriya NayakRank #47 · 31.5K reputationPosted Jul 19, 2011, 5:06 AM EDT
using System.Data.SqlClient;
public class WebForm1 : System.Web.UI.Page
{
SqlConnection con=new SqlConnection("connection string");
SqlCommand com;
SqlDataAdapter sqlda;
DataSet ds;
string str;
private void Page_Load(object sender, System.EventArgs e)
{
con.Open();
str="select * from employee";
com=new SqlCommand(str,con);
sqlda=new SqlDataAdapter(com);
ds=new DataSet();
sqlda.Fill(ds,"employee");
Gridview1.DataSource=ds;
Gridview1.DataBind();
con.Close();
}
}
Is this Helpful ? Please make this as ANSWER.