Mid
ADO.NET
ADO.NET
Bind the data to the GridView. Example: protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { SqlConnection connection = new SqlConnection(connectionString); SqlDataAdapter adapter = new SqlDataAdapter("SELECT CustomerID, CustomerName FROM Customers", connection); DataTable dataTable = new DataTable();
dapter.Fill(dataTable);
GridView1.DataSource = dataTable;
GridView1.DataBind();
}
}
Here, GridView1 is bound to the data returned from the SQL query (SELECT
CustomerID, CustomerName FROM Customers), and the DataBind() method
displays it in the grid.
Share this Q&A
Share preview image: https://www.toolliyo.com/images/toolliyo-logo.png