Note
Access to this page requires authorization. You can try signing in or changing directories.
Access to this page requires authorization. You can try changing directories.
Gets the automatically generated SqlCeCommand object required to perform updates on the database when an application calls Update on the SqlCeDataAdapter.
Namespace: System.Data.SqlServerCe
Assembly: System.Data.SqlServerCe (in system.data.sqlserverce.dll)
Syntax
'Declaration
Public Function GetUpdateCommand As SqlCeCommand
public SqlCeCommand GetUpdateCommand ()
public:
SqlCeCommand^ GetUpdateCommand ()
public SqlCeCommand GetUpdateCommand ()
public function GetUpdateCommand () : SqlCeCommand
Return Value
The automatically generated SqlCeCommand object required to perform updates.
Remarks
An application can use the GetUpdateCommand method for informational or troubleshooting purposes because it returns the SqlCeCommand object to be executed.
You can also use GetUpdateCommand as the basis of a modified command. For example, you might call GetUpdateCommand, modify one of its properties, and then explicitly set that on the SqlCeDataAdapter.
After the SQL statement is first generated, the application must explicitly call RefreshSchema if the application changes the SQL statement in any way. Otherwise, the GetUpdateCommand still uses information from the previous statement, and that information might not be correct. The SQL statements are first generated when the application calls either Update or GetUpdateCommand.
Example
The following example shows calling the GetUpdateCommand method of the SqlCeCommandBuilder.
Try
Dim conn As New SqlCeConnection("Data Source = MyDatabase.sdf")
conn.Open()
Dim cmd As SqlCeCommand = conn.CreateCommand()
cmd.CommandText = "SELECT * FROM employees"
Dim adp As New SqlCeDataAdapter(cmd)
Dim cb As New SqlCeCommandBuilder()
cb.DataAdapter = adp
MessageBox.Show(cb.GetUpdateCommand().CommandText)
MessageBox.Show(cb.GetInsertCommand().CommandText)
MessageBox.Show(cb.GetDeleteCommand().CommandText)
Dim ds As New DataSet("test")
adp.Fill(ds)
' Modify the contents of the DataSet
'
ds.Tables(0).Rows(0)("First Name") = "Joe"
adp.Update(ds)
Catch e1 As Exception
Console.WriteLine(e1.ToString())
End Try
try
{
SqlCeConnection conn = new SqlCeConnection("Data Source = MyDatabase.sdf");
conn.Open();
SqlCeCommand cmd = conn.CreateCommand();
cmd.CommandText = "SELECT * FROM employees";
SqlCeDataAdapter adp = new SqlCeDataAdapter(cmd);
SqlCeCommandBuilder cb = new SqlCeCommandBuilder();
cb.DataAdapter = adp;
MessageBox.Show(cb.GetUpdateCommand().CommandText);
MessageBox.Show(cb.GetInsertCommand().CommandText);
MessageBox.Show(cb.GetDeleteCommand().CommandText);
DataSet ds = new DataSet("test");
adp.Fill(ds);
// Modify the contents of the DataSet
//
ds.Tables[0].Rows[0]["First Name"] = "Joe";
adp.Update(ds);
}
catch (Exception e1)
{
Console.WriteLine(e1.ToString());
}
Thread Safety
Any public static (Shared in Microsoft Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.
Platforms
Development Platforms
Windows 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
Version Information
.NET Framework and NET Compact Framework
Supported in 3.5
.NET Framework
Supported in 3.0
.NET Compact Framework and .Net Framework
Supported in 2.0
See Also
Reference
SqlCeCommandBuilder Class
SqlCeCommandBuilder Members
System.Data.SqlServerCe Namespace