Click here to Skip to main content
15,791,675 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
i want to bind data to gridview how should i do it......
faisal23 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 20-Nov-12 6:27am    
thank u....can u suggest me code

1 solution

protected void Page_Load(object sender, EventArgs e)
if (!Page.IsPostBack)
string connectionString = “server=SYS2;” + “integrated security=SSPI;” +
SqlConnection myConnection;
string str_Account_Select = “SELECT * FROM AccountsTable”;
SqlCommand myCommand;
DataSet myDataSet;
myConnection = new SqlConnection(connectionString);
myCommand = new SqlCommand(str_Account_Select, myConnection);
SqlDataAdapter mySQLDataAdapter;
myDataSet = new DataSet();
mySQLDataAdapter = new SqlDataAdapter(myCommand);
mySQLDataAdapter.Fill(myDataSet, “AccountsTable”);
GridView1.DataSource = myDataSet;
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