SqlCeCommand.SqlCeCommand(String, SqlCeConnection, SqlCeTransaction) Constructor
Initializes a new instance of the SqlCeCommand class with the text of the query, a SqlCeConnection, and the SqlCeTransaction.
Namespace: System.Data.SqlServerCe
Assembly: System.Data.SqlServerCe (in system.data.sqlserverce.dll)
Syntax
'Declaration
Public Sub New ( _
commandText As String, _
connection As SqlCeConnection, _
transaction As SqlCeTransaction _
)
'Usage
Dim commandText As String
Dim connection As SqlCeConnection
Dim transaction As SqlCeTransaction
Dim instance As New SqlCeCommand(commandText, connection, transaction)
public SqlCeCommand (
string commandText,
SqlCeConnection connection,
SqlCeTransaction transaction
)
public:
SqlCeCommand (
String^ commandText,
SqlCeConnection^ connection,
SqlCeTransaction^ transaction
)
public SqlCeCommand (
String commandText,
SqlCeConnection connection,
SqlCeTransaction transaction
)
public function SqlCeCommand (
commandText : String,
connection : SqlCeConnection,
transaction : SqlCeTransaction
)
Not applicable.
Parameters
- commandText
The text of the query.
- connection
A SqlCeConnection that represents the connection to a data source.
- transaction
The transaction in which the SqlCeCommand executes.
Remarks
The following table shows initial property values for an instance of SqlCeCommand.
Properties |
Initial Value |
---|---|
cmdText |
|
Text |
|
A new SqlCeConnection that is the value for the connection parameter. |
You can change the value for any of these parameters by setting the related property.
Example
The following example creates a SqlCeCommand and sets some of its properties.
Dim cmdText As String = "INSERT INTO FactSalesQuota " & _
"(EmployeeKey, TimeKey, SalesAmountQuota) " & _
"VALUES (2, 1158, 150000.00)"
Dim conn As New SqlCeConnection("Data Source = AdventureWorks.sdf;")
conn.Open()
' Start a local transaction; SQL Mobile supports the following
' isolation levels: ReadCommitted, RepeatableRead, Serializable
'
Dim tx As SqlCeTransaction = conn.BeginTransaction(IsolationLevel.ReadCommitted)
' By default, commands run in auto-commit mode;
'
Dim cmd As New SqlCeCommand(cmdText, conn, tx)
Try
cmd.ExecuteNonQuery()
' Commit the changes to disk if everything above succeeded;
' Use Deferred mode for optimal performance; the changes will
' be flashed to disk within the timespan specified in the
' ConnectionString 'FLUSH INTERVAL' property;
'
tx.Commit(CommitMode.Deferred)
' Alternatively, you could use:
' tx.Commit(CommitMode.Immediate);
'
' or use default (Deferred) commit mode:
' tx.Commit()
Catch e As Exception
' Handle errors here
'
tx.Rollback()
Finally
conn.Close()
End Try
string cmdText = "INSERT INTO FactSalesQuota " +
"(EmployeeKey, TimeKey, SalesAmountQuota) " +
"VALUES (2, 1158, 150000.00)";
SqlCeConnection conn = new SqlCeConnection("Data Source = AdventureWorks.sdf;");
conn.Open();
// Start a local transaction; SQL Mobile supports the following
// isolation levels: ReadCommitted, RepeatableRead, Serializable
//
SqlCeTransaction tx = conn.BeginTransaction(IsolationLevel.ReadCommitted);
SqlCeCommand cmd = new SqlCeCommand(cmdText, conn, tx);
try
{
cmd.ExecuteNonQuery();
// Commit the changes to disk if everything above succeeded;
// Use Deferred mode for optimal performance; the changes will
// be flushed to disk within the timespan specified in the
// ConnectionString 'FLUSH INTERVAL' property;
//
tx.Commit(CommitMode.Deferred);
// Alternatively, you could use:
// tx.Commit(CommitMode.Immediate);
//
// or use default (Deferred) commit mode:
// tx.Commit()
}
catch (Exception)
{
// Handle errors here
//
tx.Rollback();
}
finally
{
conn.Close();
}
Platforms
Windows CE, Windows Mobile for Pocket PC, Windows Mobile for Smartphone, Windows XP Professional x64 Edition, Windows XP SP2
The Microsoft .NET Framework 3.0 is supported on Windows Vista, Microsoft Windows XP SP2, and Windows Server 2003 SP1.
Version Information
.NET Framework
Supported in: 3.0
.NET Compact Framework
Supported in: 2.0, 1.0
See Also
Reference
SqlCeCommand Class
SqlCeCommand Members
System.Data.SqlServerCe Namespace