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.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
Satyapriya NayakPosted Jul 19, 2011, 9:06 AM
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.
Jiteendra SampathiraoPosted Jul 19, 2011, 8:56 AM
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....