.NET Samples - ASP.NET Data Access

This section includes the following samples:

DataGrid18 Sample

DataGrid17 Sample

DataGrid8 Sample

DataGrid11 Sample

DataGrid1.1 Sample

DataGrid13 Sample

DataGrid7 Sample

DataGrid9 Sample

DataGrid10 Sample

DataGrid3 Sample

DataGrid1 Sample

DataGrid2 Sample

DataGrid14 Sample

DataGrid15 Sample

DataGrid6 Sample

DataGrid5 Sample

DataGrid12 Sample

DataGrid4 Sample

DataGrid16 Sample

XMLGen Sample

DataGrid18 Sample

This sample demonstrates how to separately read XML schema and data into a DataSet, and bind the data to a DataGrid control.

Namespaces used in this sample:

System; System.Data; System.IO

Classes used in this sample:

Stream; File; DataGrid; Table; StreamReader; Literal; FileStream; DataView; Font; Path; DataSet; Xml; Import; Page; Header; EventArgs; XmlSchema; Object; Style

DataGrid17 Sample

This sample demonstrates how to simultaneously read XML schema and data into a DataSet, and bind the data to a DataGrid control.

Namespaces used in this sample:

System; System.Data; System.IO

Classes used in this sample:

Table; Stream; DataGrid; File; Literal; Font; StreamReader; FileStream; Import; DataView; DataSet; Page; Xml; Style; EventArgs; Object; Header; Path

DataGrid8 Sample

This sample improves upon the DataGrid7 sample by demonstrating how other input controls might be substituted for the default text boxes provided for updating row data in a DataGrid control. This is accomplished by adding a TemplateColumn to the DataGrid control's Columns collection.

Namespaces used in this sample:

System.Data; System; System.Data.SqlClient

Classes used in this sample:

DataGrid; DataBinder; TemplateColumn; Binder; ListItem; Container; Header; SqlParameter; Type; Label; TextBox; Message; String; Style; Object; EventArgs; CommandEventArgs; DropDownList; DataGridCommandEventArgs; Control; Import; DataSet; SqlConnection; SqlCommand; CheckBox; Hash; DataAdapter; Font; SqlDataAdapter; Hashtable; SqlException; Exception; BoundColumn; Page; Table; EditCommandColumn

DataGrid11 Sample

This sample shows how to use the DataGrid control's AllowSorting property and OnSortCommand event to sort data in its columns.

Namespaces used in this sample:

System.Data; System; System.Data.SqlClient

Classes used in this sample:

DataGrid; Font; EventArgs; Import; SqlDataAdapter; DataSet; Object; DataAdapter; SqlConnection; Page; CommandEventArgs; DataGridSortCommandEventArgs; Header; DataView; Style; String; Table; Control

DataGrid1.1 Sample

This sample shows a SqlDataReader bound to a DataGrid control. The DataGrid renders a table containing the SQL data.

Namespaces used in this sample:

System.Data; System; System.Data.SqlClient

Classes used in this sample:

DataGrid; Font; SqlCommand; SqlConnection; Import; Control; Header; SqlDataReader; Object; Style; EventArgs; Page

DataGrid13 Sample

This sample demonstrates a simple master-details scenario using the DataGrid and a HyperLinkColumn to navigate to row details.

Namespaces used in this sample:

System.Data; System; System.Data.SqlClient

Classes used in this sample:

DataGrid; Font; SqlConnection; String; SqlDataAdapter; Import; DataAdapter; DataSet; Header; Object; Style; EventArgs; Page; Url; Table; Exception; Message; Form; HyperLinkColumn; HyperLink; Type; SqlParameter

DataGrid7 Sample

This sample improves upon the DataGrid6 sample by setting some of the columns in the grid to ReadOnly, to prevent them from being edited by the user.

Namespaces used in this sample:

System.Data; System; System.Data.SqlClient

Classes used in this sample:

DataGrid; Header; SqlParameter; BoundColumn; Type; Message; Style; EventArgs; String; Object; DataGridCommandEventArgs; CommandEventArgs; Font; SqlConnection; TextBox; DataAdapter; Import; SqlDataAdapter; DataSet; Control; SqlCommand; Exception; Table; Page; SqlException; EditCommandColumn

DataGrid9 Sample

This sample demonstrates how validator controls can also be added to a TemplateColumn in a DataGrid, for validating user input before a row is updated.

Namespaces used in this sample:

System.Data; System; System.Data.SqlClient

Classes used in this sample:

DataGrid; ListItem; TemplateColumn; Container; Binder; DataBinder; Font; Header; Type; SqlParameter; Label; Control; TextBox; Message; RegularExpressionValidator; RequiredFieldValidator; String; Style; Object; EventArgs; CommandEventArgs; DataGridCommandEventArgs; DropDownList; Import; SqlConnection; DataSet; SqlCommand; CheckBox; DataAdapter; Page; SqlDataAdapter; Hash; Hashtable; BoundColumn; DataRow; SqlException; DataRowView; Regex; Table; Exception; EditCommandColumn

DataGrid10 Sample

This sample demonstrates how a ButtonColumn control can be associated with the DataGrid control's DeleteCommand event, to provide a method of deleting rows in an SQL database.

Namespaces used in this sample:

System.Data; System; System.Data.SqlClient

Classes used in this sample:

DataGrid; Message; DataSet; SqlDataAdapter; Font; Object; Style; SqlConnection; SqlCommand; DataAdapter; EventArgs; Import; Header; Button; ButtonColumn; DataGridCommandEventArgs; Table; Page; CommandEventArgs; Type; Exception; SqlException; SqlParameter; String

DataGrid3 Sample

This sample uses a select query to dynamically populate a select box on the page, which guarantees that the database and user interface are always in sync.

Namespaces used in this sample:

System.Data; System; System.Data.SqlClient

Classes used in this sample:

DataGrid; SqlDataAdapter; DataAdapter; SqlConnection; DataSet; Font; EventArgs; Object; Table; Import; Page; Header; Type; String; Style; Control; SqlParameter

DataGrid1 Sample

This sample shows a DataSet bound to a DataGrid control. The DataGrid renders a table containing the SQL data.

Namespaces used in this sample:

System.Data; System; System.Data.SqlClient

Classes used in this sample:

DataGrid; SqlDataAdapter; Font; DataSet; SqlConnection; Import; DataAdapter; Style; Table; Control; Page; Header; EventArgs; Object

DataGrid2 Sample

This sample performs a parameterized select query using the SqlDataAdapter object, and binds the result to a DataGrid control.

Namespaces used in this sample:

System.Data; System; System.Data.SqlClient

Classes used in this sample:

DataGrid; SqlDataAdapter; Font; DataSet; SqlConnection; Import; DataAdapter; Style; Table; Control; SqlParameter; Type; String; Header; EventArgs; Object

DataGrid14 Sample

This sample demonstrates how to fill a DataSet from an SQL stored procedure, and bind that data to a DataGrid control.

Namespaces used in this sample:

System.Data; System; System.Data.SqlClient

Classes used in this sample:

DataGrid; SqlDataAdapter; Font; DataSet; SqlConnection; Type; DataAdapter; Import; Table; Control; Page; Header; Object; EventArgs; Style

DataGrid15 Sample

This sample demonstrates how to fill a DataSet from a parameterized SQL stored procedure, and bind that data to a DataGrid control. The parameters are read from a set of HtmlSelect controls.

Namespaces used in this sample:

System.Data; System; System.Data.SqlClient

Classes used in this sample:

DataGrid; Type; Font; DataSet; SqlParameter; SqlConnection; SqlDataAdapter; DataAdapter; Import; Control; Header; Object; Style; EventArgs; Table

DataGrid6 Sample

This sample demonstrates how to update a row of data in an SQL database from ASP.NET. The sample uses the built-in editing capabilities of the DataGrid control to construct the user interface.

Namespaces used in this sample:

System.Data; System; System.Data.SqlClient

Classes used in this sample:

DataGrid; Type; SqlParameter; Message; EventArgs; Object; String; Style; CommandEventArgs; DataGridCommandEventArgs; Font; DataSet; Control; SqlConnection; DataAdapter; SqlCommand; Import; TextBox; SqlDataAdapter; Page; Exception; Header; SqlException; Table; EditCommandColumn

DataGrid5 Sample

This sample improves upon the DataGrid4 sample by using the ASP.NET validator controls to check the user input for correctness.

Namespaces used in this sample:

System.Data; System; System.Data.SqlClient

Classes used in this sample:

Font; Type; SqlParameter; RegularExpressionValidator; RequiredFieldValidator; Control; Message; DataGrid; Page; Object; Style; SqlConnection; DataAdapter; EventArgs; Import; SqlDataAdapter; Regex; DataSet; SqlCommand; String; Table; SqlException; Exception; Header

DataGrid12 Sample

This sample builds upon the previous DataGrid11 sample, demonstrating how the SortExpression property is used to determine the field by which to sort.

Namespaces used in this sample:

System.Data; System; System.Data.SqlClient

Classes used in this sample:

Header; DataGrid; BoundColumn; Font; Import; SqlDataAdapter; DataSet; Object; Style; SqlConnection; DataAdapter; EventArgs; Page; CommandEventArgs; DataGridSortCommandEventArgs; String; DataView; Table; Control

DataGrid4 Sample

This sample demonstrates how to insert a row of data into an SQL database from ASP.NET, taking input values from the server controls on the page.

Namespaces used in this sample:

System.Data; System; System.Data.SqlClient

Classes used in this sample:

SqlParameter; Type; Message; DataGrid; Style; Font; Object; SqlDataAdapter; DataSet; SqlCommand; SqlConnection; DataAdapter; EventArgs; Import; String; Page; Exception; SqlException; Header; Table

DataGrid16 Sample

This sample demonstrates how to fill a DataSet from a parameterized SQL stored procedure, and bind that data to a DataGrid control. The parameters are read from a set of Calendar controls.

Namespaces used in this sample:

System.Data; System; System.Data.SqlClient

Classes used in this sample:

Style; Font; DataGrid; Header; Type; Calendar; DataSet; SqlParameter; SqlConnection; SqlDataAdapter; DataAdapter; Import; Table; Control; EventArgs; Object

XMLGen Sample

This sample implements a tool for selecting data from SQL and writing the result as XML data or schema text.

Namespaces used in this sample:

System.Data; System; System.Data.SqlClient

Classes used in this sample:

Xml; DataGrid; String; DataView; Font; Page; DataSet; Table; SqlConnection; DataAdapter; Import; SqlDataAdapter; Style; Object; EventArgs; Header; XmlSchema