''**********************************************************************
''* 函數名稱: UpdateDs
''* 函數描述: 更新一個DATASET,可以更新多個表,如果有一個出錯,要全部回滾事務.
''* 參數列表: arrSql:輸入DS 表格的查詢字符串數組,從下標為0處開始執行SQL語句。
''* Ds:傳入要修改的DS
''* arrTableName:DS中的表名,
''* 返 回 值: x=更新後的DS
''* 作 者: Itc-Lsg
''* 創建日期: 2007-12-22
''**********************************************************************
Public Function UpdateDs(ByVal arrSql() As String, ByRef Ds As DataSet, ByVal arrTableName() As String) As DataSet
Dim sqlcon As New SqlClIEnt.SqlConnection(Me.ConnectionString)
Dim s As SqlClIEnt.SqlCommandBuilder
Dim da As SqlClIEnt.SqlDataAdapter
Dim sTableName As String = ""
Dim strSql As String = ""
Dim nArrLen As Integer = 0
Dim i As Integer = 0
Dim tbChange As New DataTable
Dim Trans As Data.SqlClIEnt.SqlTransaction
nArrLen = arrSql.Length
If Not sqlcon.State = ConnectionState.Open Then
sqlcon.Open()
End If
Try
Trans = sqlcon.BeginTransaction
For i = 0 To nArrLen - 1
&n
bsp; strSql = arrSql(i).Trim()
sTableName = arrTableName(i)
da = New SqlClIEnt.SqlDataAdapter(strSql, sqlcon)
s = New SqlClIEnt.SqlCommandBuilder(da)
If sTableName.Trim() = "" Then
tbChange = CType(Ds.Tables(0).GetChanges, DataTable)
Else
tbChange = CType(Ds.Tables(sTableName).GetChanges, DataTable)
End If
da.SelectCommand.Transaction = Trans
If Not tbChange Is Nothing Then
If sTableName.Trim() = "" Then
da.Update(Ds)
Ds.Tables(sTableName).Clear()
da.Fill(Ds)
Else
; da.Update(Ds, sTableName)
Ds.Tables(sTableName).Clear()
da.Fill(Ds, sTableName)
End If
Ds.Merge(tbChange)
End If
Next
Ds.AcceptChanges()
Trans.Commit()
Return Ds
Catch ex As Exception
Throw ThrowErr(ex)
Trans.Rollback()
Finally
sqlcon.Close()
sqlcon.Dispose()
End Try
End Function