For DAAB, you may want to use these extension methods, the first returns a
SqlCeTransaction and some of the others let you execute a command over an
existing transaction, without having to create the command 'by hand'. At the
end you simply have to call the commit or rollback methods over the active
SqlCeTransaction method.
(VB.net)
Module DaabExtensionMethods
<Extension()> _
Public Function BeginTransaction(ByVal daabobject As
Global.Microsoft.Practices.Mobile.DataAccess.SqlDatabase) As
SqlCeTransaction
Return daabobject.GetConnection.BeginTransaction
End Function
<Extension()> _
Public Function PrepareCommand(ByVal daabobject As
Global.Microsoft.Practices.Mobile.DataAccess.SqlDatabase, ByVal commandText
As String, ByVal ParamArray parameters() As SqlCeParameter) As SqlCeCommand
Dim command As New SqlCeCommand
With command
.Connection = daabobject.GetConnection
.CommandText = commandText
.Parameters.AddRange(parameters)
.Prepare()
End With
Return command
End Function
<Extension()> _
Public Function PrepareCommand(ByVal daabobject As
Global.Microsoft.Practices.Mobile.DataAccess.SqlDatabase, ByVal transaction
As SqlCeTransaction, ByVal commandText As String, ByVal ParamArray
parameters() As SqlCeParameter) As SqlCeCommand
Dim command As New SqlCeCommand
With command
.Connection = daabobject.GetConnection
.Transaction = transaction
.CommandText = commandText
.Parameters.AddRange(parameters)
.Prepare()
End With
Return command
End Function
<Extension()> _
Public Function ExecuteNonQuery(ByVal daabobject As
Global.Microsoft.Practices.Mobile.DataAccess.SqlDatabase, ByVal transaction
As SqlCeTransaction, ByVal commandText As String, ByVal ParamArray
parameters() As SqlCeParameter) As Integer
Dim command As SqlCeCommand = daabobject.CreateCommand(transaction,
commandText, parameters)
Dim i As Integer = command.ExecuteNonQuery
command.Dispose()
Return i
End Function
<Extension()> _
Public Function CreateCommand(ByVal daabobject As
Global.Microsoft.Practices.Mobile.DataAccess.SqlDatabase, ByVal commandText
As String, ByVal ParamArray parameters() As SqlCeParameter) As SqlCeCommand
Dim command As New SqlCeCommand
With command
.Connection = daabobject.GetConnection
.CommandText = commandText
.Parameters.AddRange(parameters)
End With
Return command
End Function
<Extension()> _
Public Function CreateCommand(ByVal daabobject As
Global.Microsoft.Practices.Mobile.DataAccess.SqlDatabase, ByVal transaction
As SqlCeTransaction, ByVal commandText As String, ByVal ParamArray
parameters() As SqlCeParameter) As SqlCeCommand
Dim command As New SqlCeCommand
With command
.Connection = daabobject.GetConnection
.Transaction = transaction
.CommandText = commandText
.Parameters.AddRange(parameters)
End With
Return command
End Function
End Module
--
Alberto Silva
www.moving2u.pt - R&D Manager
http://msmvps.com/AlbertoSilva - Blog
Microsoft MVP - Device Application Development