System.Data.SqlClient.SqlDataAdapter Class

Represents a set of data commands and a database connection that are used to fill the System.Data.DataSet and update a SQL Server database. This class cannot be inherited.

See Also: SqlDataAdapter Members


[System.ComponentModel.ToolboxItem("Microsoft.VSDesigner.Data.VS.SqlDataAdapterToolboxItem, Microsoft.VSDesigner, Version=, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a")]
[System.ComponentModel.Designer("Microsoft.VSDesigner.Data.VS.SqlDataAdapterDesigner, Microsoft.VSDesigner, Version=, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a", "System.ComponentModel.Design.IDesigner")]
public sealed class SqlDataAdapter : System.Data.Common.DbDataAdapter


The System.Data.SqlClient.SqlDataAdapter, serves as a bridge between a System.Data.DataSet and SQL Server for retrieving and saving data. The System.Data.SqlClient.SqlDataAdapter provides this bridge by mapping System.Data.Common.DbDataAdapter.Fill(System.Data.DataSet), which changes the data in the System.Data.DataSet to match the data in the data source, and System.Data.Common.DbDataAdapter.Update(System.Data.DataSet), which changes the data in the data source to match the data in the System.Data.DataSet, using the appropriate Transact-SQL statements against the data source. The update is performed on a by-row basis. For every inserted, modified, and deleted row, the System.Data.Common.DbDataAdapter.Update(System.Data.DataSet) method determines the type of change that has been performed on it (Insert, Update, or Delete). Depending on the type of change, the Insert, Update, or Delete command template executes to propagate the modified row to the data source. When the System.Data.SqlClient.SqlDataAdapter fills a System.Data.DataSet, it creates the necessary tables and columns for the returned data if they do not already exist. However, primary key information is not included in the implicitly created schema unless the System.Data.Common.DataAdapter.MissingSchemaAction property is set to System.Data.MissingSchemaAction.AddWithKey. You may also have the System.Data.SqlClient.SqlDataAdapter create the schema of the System.Data.DataSet, including primary key information, before filling it with data using FillSchema. For more information, see Adding Existing Constraints to a DataSet.

System.Data.SqlClient.SqlDataAdapter is used in conjunction with System.Data.SqlClient.SqlConnection and System.Data.SqlClient.SqlCommand to increase performance when connecting to a SQL Server database.


If you are using SQL Server stored procedures to edit or delete data using a DataAdapter, make sure that you do not use SET NOCOUNT ON in the stored procedure definition. This causes the rows affected count returned to be zero, which the DataAdapter interprets as a concurrency conflict. In this event, a System.Data.DBConcurrencyException will be thrown.

The System.Data.SqlClient.SqlDataAdapter also includes the SqlDataAdapter.SelectCommand, SqlDataAdapter.InsertCommand, SqlDataAdapter.DeleteCommand, SqlDataAdapter.UpdateCommand, and System.Data.Common.DataAdapter.TableMappings properties to facilitate the loading and updating of data.

When an instance of System.Data.SqlClient.SqlDataAdapter is created, the read/write properties are set to initial values. For a list of these values, see the System.Data.SqlClient.SqlDataAdapter constructor.

The SqlDataAdapter.InsertCommand, SqlDataAdapter.DeleteCommand, and SqlDataAdapter.UpdateCommand are generic templates that are automatically filled with individual values from every modified row through the parameters mechanism.

For every column that you propagate to the data source on System.Data.Common.DbDataAdapter.Update(System.Data.DataSet), a parameter should be added to the InsertCommand, UpdateCommand, or DeleteCommand. The System.Data.Common.DbParameter.SourceColumn property of the System.Data.Common.DbParameter object should be set to the name of the column. This setting indicates that the value of the parameter is not set manually, but is taken from the particular column in the currently processed row.


An InvalidOperationException will occur if the System.Data.Common.DbDataAdapter.Fill(System.Data.DataSet) method is called and the table contains a user-defined type that is not available on the client computer. For more information, see tp:// in SQL Server Books Online.


Namespace: System.Data.SqlClient
Assembly: System.Data (in System.Data.dll)
Assembly Versions: 1.0.3300.0, 1.0.5000.0,