I never mess with table adapters or the wizard - I usually use dataadapters:
Public Function PersistTable(ByVal Table As DataTable, Optional ByVal NewRow As DataRow = Nothing) As Boolean
' adodb.PersistTable - called by any routine needing to make permanent changes in a table.
' Usually this would be midlevel procedures in IOSUBS
' PersistTable has an optional argument for appending a new row on a table.
Adapter.SelectCommand = New OleDbCommand("Select * from [" & Table.TableName & "]", con)
Dim builder As New OleDbCommandBuilder(Adapter)
builder.QuotePrefix = "["
builder.QuoteSuffix = "]"
If NewRow IsNot Nothing Then
NewRow.Item(DataRecords.ciRecordNo) = Table.Rows.Count
Table.Rows.Add(NewRow)
End If
Try
Adapter.Update(Table)
Catch e As Exception
'Throw e
MsgBox("Error persisting Table: " + Table.TableName + vbCrLf + "Exception was: " + e.Message, _
MsgBoxStyle.Information, "ADONET.PersistTable")
End Try
End Function
Public Function GetTable(ByVal tableName As String, Optional ByVal OrderRows As Boolean = True) As DataTable
' ADONET.GetTable - Called by: "Everywhere".
' Function: Given a Table name string; fill and return a datatable from an adapter
GetTable = Nothing
If con.ConnectionString = "" Then Exit Function
Dim OrderString As String = " order by RecordNo"
If Not OrderRows Then OrderString = ""
Adapter = New OleDbDataAdapter("Select * from [" & tableName & "]" & OrderString, con)
Dim result As New DataTable(tableName)
Try
Adapter.Fill(result)
Return result
Catch e As Exception
'If System.Diagnostics.Debugger.IsAttached() Then Throw e ' This is to invite making this visible on the call stack
MsgBox("Error selecting Table: " + tableName + vbCrLf + "Exception was: " + e.Message _
& vbCrLf & "The connection string is: " & vbCrLf & con.ConnectionString, _
MsgBoxStyle.Information, "ADONET.GetTable")
'result.Dispose()
'Return Nothing
End Try
'End Using
End Function
End Class
|