SqlCeCommand 构造函数 (String, SqlCeConnection, SqlCeTransaction)
使用查询文本、一个 SqlCeConnection 以及 SqlCeTransaction 来初始化 SqlCeCommand 类的新实例。
命名空间: System.Data.SqlServerCe
程序集: System.Data.SqlServerCe(在 system.data.sqlserverce.dll 中)
语法
声明
Public Sub New ( _
commandText As String, _
connection As SqlCeConnection, _
transaction As SqlCeTransaction _
)
用法
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
)
不适用。
参数
- commandText
查询的文本。
- connection
一个 SqlCeConnection,它表示与数据源的连接。
- transaction
在其中执行 SqlCeCommand 的事务。
备注
下表显示 SqlCeCommand 实例的初始属性值。
属性 |
初始值 |
---|---|
cmdText |
|
Text |
|
一个新的 SqlCeConnection,它是 connection 参数的值。 |
您可以通过设置相关属性来更改这些参数中任何参数的值。
示例
下面的示例创建一个 SqlCeCommand 并设置它的一些属性。
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();
}
平台
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