asp.net as an example,
.aspx:
<asp:DataGrid ID=”MyDataGrid” runat=”server”></asp:DataGrid>
.aspx.cs:
Assuming that Students is a database name, score is the table name
SqlConnection myConnection = new SqlConnection(“server=(local);database=students;Trusted_Connection=yes”);
// Create a new SQL connection object. The connection string of this connection is server = (local); database = students; trusted_connection = yes, indicating that the database is locally students, using Windos verification trust connection connection connection
SqlDataAdapter myCommand = new SqlDataAdapter(“select * from score”, myConnection);
// Create a SQL data adapter. This adapter is connected with the data defined earlier, and the selection command is to execute the select * from score
DataSet ds = new DataSet();
myCommand.Fill(ds);
// Create a DataSet, fill the results of the SELECT * from score query with the Fill method of the data adapter
There is a DataGrid object on the
MyDataGrid.DataSource=ds;
MyDataGrid.DataBind();
page that sets the data source of the DataGrid object to DataSet and binds data
link:
http://www.cnblogs.com/zgqys1980/archive/2008/09/02/1281873.html
Asp.net GridView Detailed Explanation (Very Complete, Classic)
http://www.blogjava.net/Hopes/articles/387501.html