using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.UI; using System.Web.UI.WebControls; using System.Data.SqlClient; using System.Data; namespace Dataset { public partial class WebForm1 : System.Web.UI.Page { //Declare ADO.Net objects private SqlConnection conn; private SqlDataAdapter da; private DataSet ds; private SqlCommandBuilder cb; protected void Page_Load(object sender, EventArgs e) { //Create connection to Northwind database SqlConnection conn = new SqlConnection(@"Data Source=.;Initial Catalog=Northwind;Integrated Security=TRUE"); //Create a SQL statement to get rows from the customers table string queryString = "SELECT CustomerID, CompanyName FROM dbo.Customers"; //Create data adapter using the connection da = new SqlDataAdapter(queryString, conn); ds = new DataSet(); //Fill the dataset using the data adapter da.Fill(ds, "Customers"); ds.Tables[0].Columns[1].ToString(); //Bind the grid to the dataset gvCustomers.DataSource = ds.Tables["Customers"]; gvCustomers.DataBind(); } protected void btnUpdate_Click(object sender, EventArgs e) { //TODO Complete update code //Create an update command using the command builder cb = new SqlCommandBuilder(da); da.UpdateCommand = cb.GetUpdateCommand(); //Update the database using the data adapter da.Update(ds.Tables["Customers"]); } } }