Assembly: System.Data.SqlServerCe (in system.data.sqlserverce.dll)
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.
When you create an instance of SqlCeDataAdapter, properties are set to their initial values. For a list of these values, see the SqlCeDataAdapter constructor.
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.
Try Dim strDataSource As String strDataSource = "" & _ "Data Source = C:\Program Files\" & _ "Microsoft SQL Server Compact Edition\v3.5\Samples\" & _ "Northwind.sdf" Dim conn As New SqlCeConnection conn.ConnectionString = strDataSource & ";Password='<password>'" Dim selectCmd As SqlCeCommand = conn.CreateCommand selectCmd.CommandText = "SELECT * FROM Employees" 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) Console.WriteLine(("The SqlCeDataAdapter succesfully filled " & _ ds.Tables.Item(0).Rows.Count & " rows in the DataSet!")) Catch ds As Exception Console.WriteLine(ds.Message) Finally Console.WriteLine(vbNewLine & vbNewLine & vbNewLine & _ "Press any key to continue...") Console.ReadKey() End Try
Development PlatformsWindows Vista, Windows Mobile 5.0, Windows XP Professional with Service Pack 2 (SP2), Windows Server 2003, Windows Mobile 2003 for Pocket PC, Windows CE 5.0
.NET Framework and NET Compact Framework
Supported in 3.5
Supported in 3.0
.NET Compact Framework and .Net Framework
Supported in 2.0