Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: ASP.NET
i want to bind data to gridview how should i do it......
Posted 20-Nov-12 0:20am
Comments
faisal23 at 20-Nov-12 6:25am
   
There are 2 ways to bind data to gv but in both you require datasource. Either by design or coding.
Member 9579525 at 20-Nov-12 6:27am
   
thank u....can u suggest me code

1 solution

Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

protected void Page_Load(object sender, EventArgs e)
{
if (!Page.IsPostBack)
{
string connectionString = “server=SYS2;” + “integrated security=SSPI;” +
“database=ERPFinAccounting”;
SqlConnection myConnection;
string str_Account_Select = “SELECT * FROM AccountsTable”;
SqlCommand myCommand;
DataSet myDataSet;
myConnection = new SqlConnection(connectionString);
myConnection.Open();
myCommand = new SqlCommand(str_Account_Select, myConnection);
SqlDataAdapter mySQLDataAdapter;
myDataSet = new DataSet();
mySQLDataAdapter = new SqlDataAdapter(myCommand);
mySQLDataAdapter.Fill(myDataSet, “AccountsTable”);
GridView1.DataSource = myDataSet;
GridView1.DataBind();
}
}
  Permalink  

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

  Print Answers RSS
Your Filters
Interested
Ignored
     
0 Shai Vashdi 1,858
1 OriginalGriff 278
2 Tadit Dash 260
3 Sergey Alexandrovich Kryukov 250
4 Peter Leow 220
0 Sergey Alexandrovich Kryukov 9,440
1 OriginalGriff 5,618
2 Peter Leow 4,280
3 Maciej Los 3,540
4 Abhinav S 3,363


Advertise | Privacy | Mobile
Web01 | 2.8.140415.2 | Last Updated 20 Nov 2012
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Use
Layout: fixed | fluid