This tutorial will show you how to connect to SQL Server using VB.NET and a SqlDataSource Control.

Design interface for insert data

Connecting the SqlDataSource Control to a Data Source

The following example shows a connection to the SQL Server Northwind sample database using a connection string stored in the configuration element.

Create “Data Command” for handle Delete, Insert,Select and Update funcition.

(The default prefix is “@” for Parameter)

Parameter Names

The data source control creates parameters automatically for the values passed in the IDictionary collections. For an insert operation, the data source control populates its InsertParameters collection with values from the name/value pairs in the Values collection. For an update operation, the data source control populates its UpdateParameters collection with values from the name/value pairs in the Keys, NewValues, and OldValues collections. For a delete operation, the data source control populates its DeleteParameters collection with values from the name/value pairs in the Keys and OldValues collections.

Create a Gridview and Bind to SqlDataSource1

The CommandField class is a special field used by data-bound controls (such as GridView and DetailsView) to display command buttons that perform delete, edit, insert, or select operations. Note: This class is new in the .NET Framework version 2.0.

Performs an insert operation using the InsertCommand SQL string and any parameters that are in the InsertParameters collection