SqlCeDataAdapter 类
表示一组数据命令和一个数据库连接,它们用于填充 DataSet 和更新数据源。
继承层次结构
System.Object
System.MarshalByRefObject
System.ComponentModel.Component
System.Data.Common.DataAdapter
System.Data.Common.DbDataAdapter
System.Data.SqlServerCe.SqlCeDataAdapter
命名空间: System.Data.SqlServerCe
程序集: System.Data.SqlServerCe(在 System.Data.SqlServerCe.dll 中)
语法
声明
Public NotInheritable Class SqlCeDataAdapter _
Inherits DbDataAdapter _
Implements ICloneable
用法
Dim instance As SqlCeDataAdapter
public sealed class SqlCeDataAdapter : DbDataAdapter,
ICloneable
public ref class SqlCeDataAdapter sealed : public DbDataAdapter,
ICloneable
[<SealedAttribute>]
type SqlCeDataAdapter =
class
inherit DbDataAdapter
interface ICloneable
end
public final class SqlCeDataAdapter extends DbDataAdapter implements ICloneable
SqlCeDataAdapter 类型公开以下成员。
构造函数
名称 | 说明 | |
---|---|---|
SqlCeDataAdapter() | 初始化 SqlCeDataAdapter 类的一个新实例。 | |
SqlCeDataAdapter(SqlCeCommand) | 初始化 SqlCeDataAdapter 类的一个新实例,用指定的 SqlCeCommand 作为 SelectCommand 的属性。 | |
SqlCeDataAdapter(String, SqlCeConnection) | 使用 SelectCommand 和 SqlCeConnection 对象初始化 SqlCeDataAdapter 类的一个新实例。 | |
SqlCeDataAdapter(String, String) | 用 SelectCommand 和一个连接字符串初始化 SqlCeDataAdapter 类的一个新实例。 |
页首
属性
名称 | 说明 | |
---|---|---|
AcceptChangesDuringFill | (继承自 DataAdapter) | |
AcceptChangesDuringUpdate | (继承自 DataAdapter) | |
CanRaiseEvents | (继承自 Component) | |
Container | (继承自 Component) | |
ContinueUpdateOnError | (继承自 DataAdapter) | |
DeleteCommand | 获取或设置用于从数据集中删除记录的 SQL 语句。 | |
DesignMode | (继承自 Component) | |
Events | (继承自 Component) | |
FillCommandBehavior | (继承自 DbDataAdapter) | |
FillLoadOption | (继承自 DataAdapter) | |
InsertCommand | 获取或设置用于将新记录插入数据源的 SQL 语句。 | |
MissingMappingAction | (继承自 DataAdapter) | |
MissingSchemaAction | (继承自 DataAdapter) | |
ReturnProviderSpecificTypes | (继承自 DataAdapter) | |
SelectCommand | 获取或设置用于在数据源中选择记录的 SQL 语句。 | |
Site | (继承自 Component) | |
TableMappings | (继承自 DataAdapter) | |
UpdateBatchSize | (继承自 DbDataAdapter) | |
UpdateCommand | 获取或设置用于更新数据源中的记录的 SQL 语句。 |
页首
方法
页首
事件
名称 | 说明 | |
---|---|---|
Disposed | (继承自 Component) | |
FillError | (继承自 DataAdapter) | |
RowUpdated | 在针对数据源执行更新命令之后的调用 Update 期间发生。试图进行更新,于是激发了此事件。 | |
RowUpdating | 在针对数据源执行更新命令之前的调用 Update 期间发生。试图进行更新,于是激发了此事件。 |
页首
显式接口实现
名称 | 说明 | |
---|---|---|
ICloneable.Clone | 有关此成员的说明,请参阅 ICloneable.Clone()。 | |
IDbDataAdapter.DeleteCommand | (继承自 DbDataAdapter) | |
IDbDataAdapter.InsertCommand | (继承自 DbDataAdapter) | |
IDbDataAdapter.SelectCommand | (继承自 DbDataAdapter) | |
IDataAdapter.TableMappings | (继承自 DataAdapter) | |
IDbDataAdapter.UpdateCommand | (继承自 DbDataAdapter) |
页首
注释
SqlCeDataAdapter 可作为 DataSet 和数据源之间的桥接器。它用于从数据源检索数据,也用于将数据保存到数据源。SqlCeDataAdapter 通过以下方法提供这个桥接器:使用 Fill 将数据从数据源加载到 DataSet 中,并使用 Update 将 DataSet 中所做的更改发回数据源。
当 SqlCeDataAdapter 填充 DataSet 时,它为返回的数据创建必要的表和列(如果这些表和列尚不存在)。但是,除非 MissingSchemaAction 属性设置为 AddWithKey,否则这个隐式创建的架构中将不包括主键信息。您也可以让 SqlCeDataAdapter 创建 DataSet 的架构,并在使用 FillSchema 向架构填充数据之前将主键信息包括进去。
SqlCeDataAdapter 包括 SelectCommand、InsertCommand、DeleteCommand、UpdateCommand 和 TableMappings 属性,为数据的加载和更新提供便利。
当创建 SqlCeDataAdapter 的实例时,属性都设置为其初始值。有关这些值的列表,请参阅 SqlCeDataAdapter 构造函数。
示例
下面的示例使用了 SqlCeCommand、SqlCeDataAdapter 和 SqlCeConnection 从数据源选择记录并用选定的行填充 DataSet。然后,将返回已填充的 DataSet。为完成此任务,向该方法传递一个已初始化的 DataSet、一个连接字符串和一个查询字符串,后者是一个 SQL SELECT 语句。
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
try
{
string strDataSource =
@"Data Source = C:\Program Files\" +
@"Microsoft SQL Server Compact Edition\v3.5\Samples\" +
@"Northwind.sdf";
SqlCeConnection conn = new SqlCeConnection();
conn.ConnectionString = strDataSource + ";Password='<password>'";
SqlCeCommand selectCmd = conn.CreateCommand();
selectCmd.CommandText = "SELECT * FROM Employees";
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);
Console.WriteLine("The SqlCeDataAdapter succesfully filled " +
ds.Tables[0].Rows.Count + " rows in the DataSet!");
}
catch (Exception ex)
{
Console.WriteLine(ex.Message);
}
finally
{
Console.WriteLine("\n\n\nPress any key to continue...");
Console.ReadKey();
}
线程安全
此类型的任何公共静态(在 Microsoft Visual Basic 中为共享)成员是线程安全的。不保证所有实例成员都对于线程安全的。