共用方式為


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
)
new : 
        selectCommandText:string * 
        selectConnectionString:string -> SqlCeDataAdapter
public function SqlCeDataAdapter(
    selectCommandText : String, 
    selectConnectionString : String
)

參數

備註

當您建立 SqlCeDataAdapter 的執行個體時,下列的讀取/寫入屬性會設定為下列的初始值。

屬性

初始值

MissingMappingAction

MissingMappingAction.Passthrough

MissingSchemaAction

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);
}

請參閱

參考

SqlCeDataAdapter 類別

SqlCeDataAdapter 多載

System.Data.SqlServerCe 命名空間

MissingMappingAction

MissingSchemaAction