|
|
|
Click here to copy the following block |
Function ExecuteBatch(ByVal connString As String, ByVal sql As String, _ ByVal params() As OleDbParameter, Optional ByVal rollback As Boolean = True) _ As Integer Dim i, start, affected As Integer Dim cn As New OleDbConnection(connString) Dim tran As OleDbTransaction Dim cmd As OleDbCommand
Dim statements() As String = sql.Split(New Char() {";"c}) Dim statement As String
Try cn.Open() tran = cn.BeginTransaction() For Each statement In statements cmd = New OleDbCommand(statement, cn) cmd.Transaction = tran Dim numParams As Integer = CountOccurrences(statement, "\?") For i = start To start + numParams - 1 cmd.Parameters.Add(params(i)) Next start = start + numParams affected += cmd.ExecuteNonQuery() Next tran.Commit() Return affected Catch e As Exception If rollback Then tran.Rollback() Throw e Finally If Not rollback Then tran.Commit() cn.Close() End Try End Function |
|
|
|
Submitted By :
Nayan Patel
(Member Since : 5/26/2004 12:23:06 PM)
|
|
|
Job Description :
He is the moderator of this site and currently working as an independent consultant. He works with VB.net/ASP.net, SQL Server and other MS technologies. He is MCSD.net, MCDBA and MCSE. In his free time he likes to watch funny movies and doing oil painting. |
View all (893) submissions by this author
(Birth Date : 7/14/1981 ) |
|
|