More Ways to Update Databases using ASP.NET 2.0 SqlDataSource
(Page 1 of 5 )
In the previous article, we saw how to insert a new record using the SqlDataSource control, programmatically, by assigning appropriate values for the SqlDataSource.InsertCommand property, SqlDataSoruce.InsertParameters collection property and calling the SqlDataSource.Insert() method. Today we will write code to update the Northwind's Employees table and provide the delete functionality.
Note that in this article we explain the basics so when we discuss how the Data-Bound Controls work with the SqlDataSource control you wouldn't feel lost. If you have used the Visual Studio.NET 2005 Task Menu feature, for a SqlDataSource Control as we did in the article "Introduction to the ASP.NET 2.0 SqlDataSource Control," you may have noticed that it generates the SELECT, INSERT, UPDATE and DELETE statements for the SqlDataSource control that is set as the Data Source for the GridView.
Those statements may be parameterized queries too, so where do the values of the parameters come from? And in what syntax? What are the default names for the parameters? All of these questions will be answered when we discuss the Data-Bound Controls. But today we discuss the basic concepts of updating and deleting data in databases using the SqlDataSource control. So let's start with our code example.
We are going to have two pages for this example. The first web page is going to use a SqlDataSource control (declaratively) to retrieve data from the Employees table into a ListBox control. The second page will be used to update a record in the Employees table.
Usually you will use a Data-Bound Control to perform the Update, Delete and Insert operations, but in this article we write the code without using a Data-Bound Control. So let's begin developing the first page.
Next: Using a ListBox and a SqlDataSource control for Default.aspx page >>
More ASP.NET Articles
More By Michael Youssef