SqlCeDataAdapter 构造函数 (String, String)
用 SelectCommand 和一个连接字符串初始化 SqlCeDataAdapter 类的新实例。
命名空间: System.Data.SqlServerCe
程序集: System.Data.SqlServerCe(在 system.data.sqlserverce.dll 中)
语法
声明
Public Sub New ( _
selectCommandText As String, _
selectConnectionString As String _
)
用法
Dim selectCommandText As String
Dim selectConnectionString As String
Dim instance As New SqlCeDataAdapter(selectCommandText, selectConnectionString)
public SqlCeDataAdapter (
string selectCommandText,
string selectConnectionString
)
public:
SqlCeDataAdapter (
String^ selectCommandText,
String^ selectConnectionString
)
public SqlCeDataAdapter (
String selectCommandText,
String selectConnectionString
)
public function SqlCeDataAdapter (
selectCommandText : String,
selectConnectionString : String
)
不适用。
参数
- selectCommandText
一个 String,它是一个 SQL SELECT 语句,将被用作 SqlCeDataAdapter 的 SelectCommand 属性的 CommandText。
- selectConnectionString
备注
当创建 SqlCeDataAdapter 的实例时,下面的读/写属性将设置为以下初始值。
属性 |
初始值 |
---|---|
MissingMappingAction.Passthrough |
|
MissingSchemaAction.Add |
可以通过单独调用这些属性中某个属性来更改该属性的值。
示例
下面的示例通过传入命令文本和连接字符串创建了一个 SqlCeDataAdapter。
Public Sub Snippet5()
' Create DataAdapter
'
Dim adp As New SqlCeDataAdapter("SELECT * FROM products", "Data Source = MyDatabase.sdf")
Dim cb As New SqlCeCommandBuilder(adp)
' Create and fill the dataset (select only first 5 rows)
'
Dim ds As New DataSet()
adp.Fill(ds, 0, 5, "Table")
' Modify dataSet
'
Dim table As DataTable = ds.Tables("Table")
table.Rows(1)("Product Name") = "Asian Chai"
' Add handlers
'
AddHandler adp.RowUpdating, AddressOf OnRowUpdating
AddHandler adp.RowUpdated, AddressOf OnRowUpdated
' Update, this operation fires two events (RowUpdating/RowUpdated)
'
adp.Update(ds, "Table")
' Remove handlers
'
RemoveHandler adp.RowUpdating, AddressOf OnRowUpdating
RemoveHandler adp.RowUpdated, AddressOf OnRowUpdated
End Sub 'Snippet5
Private Shared Sub OnRowUpdating(ByVal sender As Object, ByVal e As SqlCeRowUpdatingEventArgs)
Console.WriteLine("OnRowUpdating")
Console.WriteLine(e.Command.CommandText)
Console.WriteLine(e.StatementType)
Console.WriteLine(e.Status)
End Sub 'OnRowUpdating
Private Shared Sub OnRowUpdated(ByVal sender As Object, ByVal e As SqlCeRowUpdatedEventArgs)
Console.WriteLine("OnRowUpdated")
Console.WriteLine(e.Command.CommandText)
Console.WriteLine(e.StatementType)
Console.WriteLine(e.Status)
End Sub 'OnRowUpdated
public void Snippet5()
{
// Create DataAdapter
//
SqlCeDataAdapter adp = new SqlCeDataAdapter(
"SELECT * FROM products",
"Data Source = MyDatabase.sdf");
SqlCeCommandBuilder cb = new SqlCeCommandBuilder(adp);
// Create and fill the dataset (select only first 5 rows)
//
DataSet ds = new DataSet();
adp.Fill(ds, 0, 5, "Table");
// Modify dataSet
//
DataTable table = ds.Tables["Table"];
table.Rows[1]["Product Name"] = "Asian Chai";
// Add handlers
//
adp.RowUpdating += new SqlCeRowUpdatingEventHandler(OnRowUpdating);
adp.RowUpdated += new SqlCeRowUpdatedEventHandler(OnRowUpdated);
// Update, this operation fires two events (RowUpdating/RowUpdated)
//
adp.Update(ds, "Table");
// Remove handlers
//
adp.RowUpdating -= new SqlCeRowUpdatingEventHandler(OnRowUpdating);
adp.RowUpdated -= new SqlCeRowUpdatedEventHandler(OnRowUpdated);
}
private static void OnRowUpdating(object sender, SqlCeRowUpdatingEventArgs e)
{
Console.WriteLine("OnRowUpdating");
Console.WriteLine(e.Command.CommandText);
Console.WriteLine(e.StatementType);
Console.WriteLine(e.Status);
}
private static void OnRowUpdated(object sender, SqlCeRowUpdatedEventArgs e)
{
Console.WriteLine("OnRowUpdated");
Console.WriteLine(e.Command.CommandText);
Console.WriteLine(e.StatementType);
Console.WriteLine(e.Status);
}
平台
Windows 98, Windows Server 2000 SP4, Windows CE, Windows Millennium Edition, Windows Mobile for Pocket PC, Windows Mobile for Smartphone, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition
Windows Vista、Microsoft Windows XP SP2 和 Windows Server 2003 SP1 支持 Microsoft .NET Framework 3.0。
版本信息
.NET Framework
受以下版本支持:3.0
.NET Compact Framework
受以下版本支持:2.0、1.0
请参见
参考
SqlCeDataAdapter 类
SqlCeDataAdapter 成员
System.Data.SqlServerCe 命名空间
MissingMappingAction
MissingSchemaAction