Database Reference
In-Depth Information
Figure 16-9.
The Design view of WebDataForm with a Repeater control
4. Now you need to bind the data access code to WebDataForm. Double-click the
empty surface of the WebDataForm as you have done already in Windows
Forms applications. This will open the
Page_Load
event.
5. Modify the
Page_Load
event of
WebDataForm.aspx.cs
to look like Listing 16-2.
Listing 16-2.
WebDataForm.aspx.cs
using System.Data;
using System.Data.SqlClient
protected void Page_Load(object sender, EventArgs e)
{
// Connection string
string connString = @"server=.\sql2012;database=AdventureWorks;
Integrated Security=true";
//Query
string query = @" SELECT Title, BirthDate
FROM HumanResources.Employee";
DataTable dt = new DataTable();
try
{
SqlDataAdapter da = new SqlDataAdapter(query, connString);
da.Fill(dt);
}