Public Class _Extern_Datas
Private Shared cat As ADOX.Catalog
Public Event Protokoll(ByVal str As String, ByVal bWriteInListBox _
As Boolean)
Public Sub New()
cat = New ADOX.Catalog
cn = New ADODB.Connection
cn.ConnectionString = m_ConnectionString
cn.Open()
cat.ActiveConnection = cn
End Sub
Public Sub Dispose()
cat = Nothing
cn.Close()
cn = Nothing
End Sub
Public Sub CreateLink(ByVal Database As String, ByVal TableName As _
String)
Try
Dim dt As DataTable = cDataBase.CreateDataTable("SELECT *" & _
"FROM " & TableName)
If Not dt Is Nothing Then
dt = Nothing
RaiseEvent Protokoll("Verknüpfung " & TableName & "" & _
"bereits vorhanden", True)
Exit Sub
End If
Dim Tbl As ADOX.Table
'Tabelle beschreiben, Link setzten
Tbl = New ADOX.Table
With Tbl
.ParentCatalog = cat
.Name = TableName
End With
Dim Props As ADOX.Properties
Props = Tbl.Properties
Dim PropDS As ADOX.Property, PropPS As ADOX.Property, _
PropRTN As ADOX.Property, PropCL As ADOX.Property
PropPS = Props.Item("Jet OLEDB:Link Provider String")
PropPS.Value = "MS Access"
PropDS = Props.Item("Jet OLEDB:Link Datasource")
PropDS.Value = Database
PropRTN = Props.Item("Jet OLEDB:Remote Table Name")
PropRTN.Value = TableName
PropCL = Props.Item("Jet OLEDB:Create Link")
PropCL.Value = True
Props.Refresh()
'aufnehmen in Collection
cat.Tables.Append(Tbl)
RaiseEvent Protokoll("Tabelle " & TableName & " aus " & _
Database & " verknüpft", True)
'aufräumen
Tbl = Nothing
Catch ex As Exception
RaiseEvent Protokoll("Extern_Datas_Createlink " & _
ex.Message, False)
End Try
End Sub
Public Sub DeleteLink(ByVal TableName As String)
Try
Dim bExist As Boolean = False
For Each tab As ADOX.Table In cat.Tables
If tab.Name = TableName Then
bExist = True
End If
Next
If bExist = False Then
RaiseEvent Protokoll("Verknüpfung " & TableName & "" & _
"bereits gelöscht", True)
Exit Sub
End If
'Verknüpfung löschen
cat.Tables.Delete(TableName)
RaiseEvent Protokoll("Verknüpfung " & TableName & " wurde" & _
"gelöscht", True)
Catch ex As Exception
RaiseEvent Protokoll("Extern_Datas_DeleteLink " & _
ex.Message, False)
End Try
End Sub
end class das event protokoll, kannst Du mit Addhandler an eine funktion hängen, die dann den text einerseits in eine textdatei schreibt, und mit true hintendrann, wird es in eine listbox geschrieben
Private Sub Protokoll(ByVal str As String, ByVal bWriteInListBox As _
Boolean)
cIO.File.WriteLine(m_ApplicationPath & "Modify.ini", Now.ToString( _
"dd.MM.yyyy HH:mm:ss") & " " & str)
If bWriteInListBox = True And Not m_lst Is Nothing Then
m_lst.Items.Add(CType(str, String))
m_lst.Refresh()
Application.DoEvents()
End If
End Sub
Public Class cIO
Public Shared Sub WriteLine(ByVal Path As String, ByVal Text As String)
Dim fs As New StreamWriter(Path, True)
fs.WriteLine(Text)
fs.Close()
End Sub
end Class 0 |