摘要:CTable
01
Public Function CreateUpdateTable(ByVal sql As String, ByVal ptableName As String, ByVal mytrans As SqlTransaction, ByRef padapter As SqlDataAdapter, ByRef ds As DataSet) As DataTable
02
'Try
03
command = New SqlCommand(sql, Tbconn)
04
trans = mytrans
05
command.Transaction = mytrans
06
If Not (trans Is Nothing) Then
07
command.Transaction = trans
08
End If
09
'If (trans Is Nothing) Then
10
' MsgBox1(sql + "-->用此function 必須用transaction")
11
' Return Nothing
12
'End If
13
14
15
adapter = New SqlDataAdapter(command)
16
builder = New SqlCommandBuilder(adapter)
17
18
Console.WriteLine(builder.GetInsertCommand().CommandText)
19
Try
20
Console.WriteLine(builder.GetUpdateCommand().CommandText)
21
Catch
22
End Try
23
ds = New DataSet
24
adapter.Fill(ds, ptableName)
25
table = ds.Tables(ptableName)
26
'adapter.Fill(table)
27
tableName = ptableName
28
padapter = adapter
29
30
Return table
31
'Catch ex As Exception
32
' errMsg = ClassName & vbCrLf + "CTable.CreateUpdateTable" & vbCrLf + CStr(connData.State) & vbCrLf + sql & vbCrLf & ex.Message
33
' Dim e As New Exception(errMsg)
34
' Throw e
35
36
'End Try
37
38
39
End Function
Public Function CreateUpdateTable(ByVal sql As String, ByVal ptableName As String, ByVal mytrans As SqlTransaction, ByRef padapter As SqlDataAdapter, ByRef ds As DataSet) As DataTable 02
'Try 03
command = New SqlCommand(sql, Tbconn) 04
trans = mytrans 05
command.Transaction = mytrans 06
If Not (trans Is Nothing) Then 07
command.Transaction = trans 08
End If 09
'If (trans Is Nothing) Then 10
' MsgBox1(sql + "-->用此function 必須用transaction") 11
' Return Nothing 12
'End If 13
14
15
adapter = New SqlDataAdapter(command) 16
builder = New SqlCommandBuilder(adapter) 17
18
Console.WriteLine(builder.GetInsertCommand().CommandText) 19
Try 20
Console.WriteLine(builder.GetUpdateCommand().CommandText) 21
Catch 22
End Try 23
ds = New DataSet 24
adapter.Fill(ds, ptableName) 25
table = ds.Tables(ptableName) 26
'adapter.Fill(table) 27
tableName = ptableName 28
padapter = adapter 29
30
Return table 31
'Catch ex As Exception 32
' errMsg = ClassName & vbCrLf + "CTable.CreateUpdateTable" & vbCrLf + CStr(connData.State) & vbCrLf + sql & vbCrLf & ex.Message 33
' Dim e As New Exception(errMsg) 34
' Throw e 35
36
'End Try 37
38
39
End Function
Public