SqlCeDataAdapter コンストラクタ (String, SqlCeConnection)
アセンブリ: System.Data.SqlServerCe (system.data.sqlserverce.dll 内)
構文
Dim selectCommandText As String Dim selectConnection As SqlCeConnection Dim instance As New SqlCeDataAdapter(selectCommandText, selectConnection)
- selectCommandText
SQL SELECT ステートメントである String。この文字列は、SqlCeDataAdapter の SelectCommand プロパティの CommandText として使用されます。
- selectConnection
接続を表す SqlCeConnection。
SqlCeDataAdapter の実装では、SqlCeConnection が開いていない場合は、接続が開かれ、再び閉じられます。これは、アプリケーションで複数の SqlCeDataAdapter オブジェクトの Fill メソッドを呼び出す必要がある場合に効果的です。SqlCeConnection が既に開いている場合、その接続を閉じるには、明示的に Close または Dispose を呼び出す必要があります。
SqlCeDataAdapter のインスタンスを作成すると、次のように読み取り/書き込みプロパティが初期値に設定されます。
MissingMappingAction | MissingMappingAction.Passthrough |
MissingSchemaAction | MissingSchemaAction.Add |
.NET Framework のセキュリティ
プラットフォーム
Windows CE, Windows Mobile for Pocket PC, Windows Mobile for Smartphone, Windows XP Professional x64 Edition, Windows XP SP2
開発プラットフォームの中には、.NET Framework によってサポートされていないバージョンがあります。サポートされているバージョンについては、「システム要件」を参照してください。
参照
SqlCeDataAdapter コンストラクタ (String, String)
アセンブリ: System.Data.SqlServerCe (system.data.sqlserverce.dll 内)
構文
Dim selectCommandText As String Dim selectConnectionString As String Dim instance As New SqlCeDataAdapter(selectCommandText, selectConnectionString)
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); }
プラットフォーム
Windows CE, Windows Mobile for Pocket PC, Windows Mobile for Smartphone, Windows XP Professional x64 Edition, Windows XP SP2
開発プラットフォームの中には、.NET Framework によってサポートされていないバージョンがあります。サポートされているバージョンについては、「システム要件」を参照してください。
参照
SqlCeDataAdapter コンストラクタ (SqlCeCommand)
アセンブリ: System.Data.SqlServerCe (system.data.sqlserverce.dll 内)
構文
- selectCommand
SELECT ステートメントである SqlCeCommand。この SqlCeCommand は、SqlCeDataAdapter の SelectCommand プロパティとして設定されます。
このコンストラクタでは、selectCommand パラメータで指定した値が SelectCommand プロパティに設定されます。
SqlCeDataAdapter のインスタンスを作成すると、次のように読み取り/書き込みプロパティが初期値に設定されます。
MissingMappingAction | MissingMappingAction.Passthrough |
MissingSchemaAction | MissingSchemaAction.Add |
.NET Framework のセキュリティ
プラットフォーム
Windows CE, Windows Mobile for Pocket PC, Windows Mobile for Smartphone, Windows XP Professional x64 Edition, Windows XP SP2
開発プラットフォームの中には、.NET Framework によってサポートされていないバージョンがあります。サポートされているバージョンについては、「システム要件」を参照してください。
参照
SqlCeDataAdapter コンストラクタ
オーバーロードの一覧
名前 | 説明 |
---|---|
SqlCeDataAdapter () | SqlCeDataAdapter クラスの新しいインスタンスを初期化します。 .NET Compact Framework によってサポートされています。 |
SqlCeDataAdapter (SqlCeCommand) | SelectCommand プロパティとして SqlCeCommand を指定して、SqlCeDataAdapter クラスの新しいインスタンスを初期化します。 .NET Compact Framework によってサポートされています。 |
SqlCeDataAdapter (String, SqlCeConnection) | SelectCommand オブジェクトと SqlCeConnection オブジェクトを指定して、SqlCeDataAdapter クラスの新しいインスタンスを初期化します。 .NET Compact Framework によってサポートされています。 |
SqlCeDataAdapter (String, String) | SelectCommand と接続文字列を指定して、SqlCeDataAdapter クラスの新しいインスタンスを初期化します。 .NET Compact Framework によってサポートされています。 |
SqlCeDataAdapter コンストラクタ ()
アセンブリ: System.Data.SqlServerCe (system.data.sqlserverce.dll 内)
構文
解説
SqlCeDataAdapter のインスタンスを作成すると、次のように読み取り/書き込みプロパティが初期値に設定されます。
MissingMappingAction | MissingMappingAction.Passthrough |
MissingSchemaAction | MissingSchemaAction.Add |
SqlCeDataAdapter を作成し、そのプロパティの一部を設定する例を次に示します。
Dim cmd As SqlCeCommand = Nothing Dim adp As SqlCeDataAdapter = Nothing Try adp = New SqlCeDataAdapter() Dim conn As New SqlCeConnection("Data Source = MyDatabase.sdf") ' Create the SelectCommand ' cmd = conn.CreateCommand() cmd.CommandText = "SELECT [Employee ID], [First Name], [Last Name] FROM Employees" adp.SelectCommand = cmd ' Create the InsertCommand ' cmd = conn.CreateCommand() cmd.CommandText = "INSERT INTO Employees ([First Name],[Last Name]) VALUES (@first, @last)" Dim p As SqlCeParameter = Nothing p = cmd.Parameters.Add("@first", SqlDbType.NVarChar, 10, "First Name") p.SourceVersion = DataRowVersion.Original p = cmd.Parameters.Add("@last", SqlDbType.NVarChar, 20, "Last Name") p.SourceVersion = DataRowVersion.Original adp.InsertCommand = cmd ' Create the UpdateCommand ' cmd = conn.CreateCommand() cmd.CommandText = "UPDATE Employees SET [First Name] = @first, " + _ "[Last Name] = @last WHERE [Employee ID] = @employeeID" p = cmd.Parameters.Add("@first", SqlDbType.NVarChar, 10, "First Name") p.SourceVersion = DataRowVersion.Current p = cmd.Parameters.Add("@last", SqlDbType.NVarChar, 20, "Last Name") p.SourceVersion = DataRowVersion.Current p = cmd.Parameters.Add("@employeeID", SqlDbType.NVarChar, 20, "Employee ID") p.SourceVersion = DataRowVersion.Original adp.UpdateCommand = cmd ' Populate the dataset with the results from the SELECT statement ' Dim ds As New DataSet() adp.Fill(ds) ' Modify the dataset ' MessageBox.Show("Number of rows: " & ds.Tables(0).Rows.Count) ' Insert some rows ' ds.Tables(0).Rows.Add(New Object() {Nothing, "Nancy", "Smith"}) ds.Tables(0).Rows.Add(New Object() {Nothing, "Joe", "Clayton"}) ' Update some rows ' ds.Tables(0).Rows(1)(1) = "David" ds.Tables(0).Rows(1)(2) = "Johnson" ' This will execute two INSERT and one UPDATE statements ' adp.Update(ds.Tables(0)) Catch e As Exception MessageBox.Show(e.Message) Finally If Not Nothing Is adp.SelectCommand Then adp.SelectCommand.Dispose() End If If Not Nothing Is adp.InsertCommand Then adp.InsertCommand.Dispose() End If End Try
SqlCeCommand cmd = null; SqlCeDataAdapter adp = null; try { adp = new SqlCeDataAdapter(); SqlCeConnection conn = new SqlCeConnection("Data Source = MyDatabase.sdf"); // Create the SelectCommand // cmd = conn.CreateCommand(); cmd.CommandText = "SELECT [Employee ID], [First Name], [Last Name] FROM Employees"; adp.SelectCommand = cmd; // Create the InsertCommand // cmd = conn.CreateCommand(); cmd.CommandText = "INSERT INTO Employees ([First Name],[Last Name]) VALUES (@first, @last)"; SqlCeParameter p = null; p = cmd.Parameters.Add("@first", SqlDbType.NVarChar, 10, "First Name"); p.SourceVersion = DataRowVersion.Original; p = cmd.Parameters.Add("@last", SqlDbType.NVarChar, 20, "Last Name"); p.SourceVersion = DataRowVersion.Original; adp.InsertCommand = cmd; // Create the UpdateCommand // cmd = conn.CreateCommand(); cmd.CommandText = "UPDATE Employees SET [First Name] = @first, " + "[Last Name] = @last WHERE [Employee ID] = @employeeID"; p = cmd.Parameters.Add("@first", SqlDbType.NVarChar, 10, "First Name"); p.SourceVersion = DataRowVersion.Current; p = cmd.Parameters.Add("@last", SqlDbType.NVarChar, 20, "Last Name"); p.SourceVersion = DataRowVersion.Current; p = cmd.Parameters.Add("@employeeID", SqlDbType.NVarChar, 20, "Employee ID"); p.SourceVersion = DataRowVersion.Original; adp.UpdateCommand = cmd; // Populate the dataset with the results from the SELECT statement // DataSet ds = new DataSet(); adp.Fill(ds); // Modify the dataset // MessageBox.Show("Number of rows: " + ds.Tables[0].Rows.Count); // Insert some rows // ds.Tables[0].Rows.Add(new object[] { null, "Nancy", "Smith" }); ds.Tables[0].Rows.Add(new object[] { null, "Joe", "Clayton" }); // Update some rows // ds.Tables[0].Rows[1][1] = "David"; ds.Tables[0].Rows[1][2] = "Johnson"; // This will execute two INSERT and one UPDATE statements // adp.Update(ds.Tables[0]); } catch (Exception e) { MessageBox.Show(e.Message); } finally { if (null != adp.SelectCommand) adp.SelectCommand.Dispose(); if (null != adp.InsertCommand) adp.InsertCommand.Dispose(); }
プラットフォーム
Windows CE, Windows Mobile for Pocket PC, Windows Mobile for Smartphone, Windows XP Professional x64 Edition, Windows XP SP2
開発プラットフォームの中には、.NET Framework によってサポートされていないバージョンがあります。サポートされているバージョンについては、「システム要件」を参照してください。
参照
- SqlCeDataAdapter コンストラクタのページへのリンク