共用方式為


SqlCeDataAdapter Class

Represents a set of data commands and a database connection that are used to fill the DataSet and update the data source.

Namespace: System.Data.SqlServerCe
Assembly: System.Data.SqlServerCe (in system.data.sqlserverce.dll)

Syntax

'Declaration
Public NotInheritable Class SqlCeDataAdapter
    Inherits DbDataAdapter
    Implements ICloneable
'Usage
Dim instance As SqlCeDataAdapter
public sealed class SqlCeDataAdapter : DbDataAdapter, ICloneable
public ref class SqlCeDataAdapter sealed : public DbDataAdapter, ICloneable
public final class SqlCeDataAdapter extends DbDataAdapter implements ICloneable
public final class SqlCeDataAdapter extends DbDataAdapter implements ICloneable
Not applicable.

Remarks

The SqlCeDataAdapter serves as a bridge between a DataSet and data source. It is used for retrieving data from, and saving data to, the data source. The SqlCeDataAdapter provides this bridge by using Fill to load data from the data source into the DataSet, and using Update to send changes made in the DataSet back to the data source.

When the SqlCeDataAdapter fills a DataSet, it creates the necessary tables and columns for the returned data if they do not already exist. However, primary key information will not be included in the implicitly created schema unless the MissingSchemaAction property is set to AddWithKey. You can also have the SqlCeDataAdapter create the schema of the DataSet, including primary key information, before filling it with data by using FillSchema.

The SqlCeDataAdapter includes the SelectCommand, InsertCommand, DeleteCommand, UpdateCommand, and TableMappings properties to facilitate the loading and updating of data.

When you create an instance of SqlCeDataAdapter, properties are set to their initial values. For a list of these values, see the SqlCeDataAdapter constructor.

Example

The following example uses the SqlCeCommand, SqlCeDataAdapter, and SqlCeConnection to select records from a data source and populate a DataSet with the selected rows. The populated DataSet is then returned. To accomplish this, the method is passed an initialized DataSet, a connection string, and a query string that is an SQL SELECT statement.

Dim conn As New SqlCeConnection("Data Source = AdventureWorks.sdf")

Dim selectCmd As SqlCeCommand = conn.CreateCommand()
selectCmd.CommandText = "SELECT * FROM DimEmployee"

Dim adp As New SqlCeDataAdapter(selectCmd)

Dim ds As New DataSet()

' Note: Fill will leave the connection in its original state;
' In this case, the connection was closed so it will be left closed
'
adp.Fill(ds)
SqlCeConnection conn = new SqlCeConnection("Data Source = AdventureWorks.sdf");

SqlCeCommand selectCmd = conn.CreateCommand();
selectCmd.CommandText = "SELECT * FROM DimEmployee";

SqlCeDataAdapter adp = new SqlCeDataAdapter(selectCmd);

DataSet ds = new DataSet();

// Note: Fill will leave the connection in its original state;
// In this case, the connection was closed so it will be left closed
//
adp.Fill(ds);

Inheritance Hierarchy

System.Object
   System.MarshalByRefObject
     System.ComponentModel.Component
       System.Data.Common.DataAdapter
         System.Data.Common.DbDataAdapter
          System.Data.SqlServerCe.SqlCeDataAdapter

Thread Safety

Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.

Platforms

Windows CE, Windows Mobile for Pocket PC, Windows Mobile for Smartphone, Windows XP Professional x64 Edition, Windows XP SP2

The Microsoft .NET Framework 3.0 is supported on Windows Vista, Microsoft Windows XP SP2, and Windows Server 2003 SP1.

Version Information

.NET Framework

Supported in: 3.0

.NET Compact Framework

Supported in: 2.0, 1.0

See Also

Reference

SqlCeDataAdapter Members
System.Data.SqlServerCe Namespace
SqlCeConnection
SqlCeCommand
DataSet
DataTable