O'Reilly logo

Programming ASP .NET by Dan Hurwitz, Jesse Liberty

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Command Builder

In the previous section, you painstakingly created the update, insert, and delete commands. You first created stored procedures, and then you created command objects for each procedure, passing in the necessary parameters. ASP.NET will do a lot of this work for you, if the update, insert, and delete commands are simple enough.

ASP.NET provides a Command Builder (SqlCommandBuilder and OleDbCommandBuilder) to generate the necessary delete, update, and insert commands without your writing stored procedures. To take advantage of these objects, the following conditions must be met:

  • The rows in the table you are generating must have come from a single table in the database.

  • The table must have a primary key or a field with values guaranteed to be unique.

  • The unique value column must be returned by the query used to fill the dataset (the select command).

  • The name of the table must not have spaces, periods, quotation marks, or other special characters.

To see how using the command builder classes simplifies the task when these conditions are met, you’ll modify the program to build the dataset only from the Bugs table. Your user interface will be much simpler because you’ll use a very simple Select statement, Select * from Bugs.

Strip down the .aspx page, and do not use custom columns; allow the data grid to get its value right from its source table. Discard the BugHistory data grid, since you won’t be using it for this example. The complete .aspx page is shown in Example ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required