DAtabase integriert

This commit is contained in:
2023-05-22 16:55:44 +02:00
parent 2db575d944
commit c2deb54f11
114 changed files with 8526 additions and 14722 deletions

View File

@@ -151,10 +151,10 @@ Public Class frmSAP_FuBa
End If
'######
Dim i = 0
Dim tablename = "[TBPMO_SAP_" & TempTableNameTextBox.Text & "]"
ClassDatabase.Execute_non_Query_withConn("DROP TABLE " & tablename, 1)
Dim oTablename = "[TBPMO_SAP_" & TempTableNameTextBox.Text & "]"
MYDB_ECM.ExecuteNonQuery("DROP TABLE " & oTablename)
Dim createtablesql = "CREATE TABLE " & tablename & " ( "
Dim createtablesql = "CREATE TABLE " & oTablename & " ( "
For Each col As System.Data.DataColumn In SAPResulttable.Columns
If i = 0 Then
createtablesql += "[" & col.ColumnName & "] [varchar](250)"
@@ -163,49 +163,30 @@ Public Class frmSAP_FuBa
End If
i += 1
Next
createtablesql += ", [ADDED_WHEN] DATETIME NOT NULL DEFAULT GETDATE()"
createtablesql += ")"
''Die Tabelle anlegen
LOGGER.Debug("Create Table: " & createtablesql)
If ClassDatabase.Execute_non_Query_withConn(createtablesql, 1) = False Then
If MYDB_ECM.ExecuteNonQuery(createtablesql) = False Then
MsgBox("Error in creating TempTable: Check log", MsgBoxStyle.Critical)
Exit Sub
End If
LOGGER.Debug("table has been created")
Dim alter = String.Format("ALTER TABLE {0} ADD GUID INTEGER NOT NULL IDENTITY(1,1)", tablename)
ClassDatabase.Execute_non_Query_withConn(alter, 1)
'Dim del = "delete from " & tablename
'ClassDatabase.Execute_non_Query_withConn(del, 1)
'If ClassDatabase.Execute_non_Query_withConn(createtablesql, 1) = False Then
' Me.Cursor = Cursors.Default
' MsgBox("Error while creating the temporary table. Please check the logfile!", MsgBoxStyle.Critical)
' Exit Sub
'End If
'Dim ins = "Insert into " & tablename & "("
'Dim DT As DataTable = ClassDatabase.Return_Datatable("SELECT * FROM " & tablename)
'If Not IsNothing(DT) Then
' Dim anz As Integer = 0
' For Each col As DataColumn In DT.Columns
' If anz = 0 Then
' ins = ins & col.ColumnName
' Else
' ins = ins & ", " & col.ColumnName
' End If
' anz += 1
' Next
' ins = ins & ") VALUES ("
'End If
Dim alter = String.Format("ALTER TABLE {0} ADD GUID INTEGER NOT NULL IDENTITY(1,1)", oTablename)
MYDB_ECM.ExecuteNonQuery(alter)
Try
Dim OwnerCS As String
OwnerCS = ClassDatabase.GetConnectionString(1)
'Dim OwnerCS As String
'OwnerCS = ClassDatabase.GetConnectionString(1)
Dim SQLconnect As New SqlClient.SqlConnection
SQLconnect.ConnectionString = OwnerCS
SQLconnect.ConnectionString = MYDB_ECM.CurrentConnectionString
SQLconnect.Open()
' Note that the column positions in the source DataTable
' match the column positions in the destination table,
' so there is no need to map columns.
Using bulkCopy As SqlBulkCopy = New SqlBulkCopy(SQLconnect)
bulkCopy.DestinationTableName = tablename
bulkCopy.DestinationTableName = oTablename
Try
' Write from the source to the destination.
bulkCopy.WriteToServer(SAPResulttable)
@@ -215,8 +196,8 @@ Public Class frmSAP_FuBa
End Using
SQLconnect.Close()
Me.Cursor = Cursors.Default
LOGGER.Debug("Create table from SAP FuBa was successfull " & SAPResulttable.Rows.Count & " Rows were inserted to table '" & tablename & "'!")
MsgBox("Create table was successfull! " & vbNewLine & SAPResulttable.Rows.Count & " Rows were inserted to table '" & tablename & "'!", MsgBoxStyle.Information)
LOGGER.Debug("Create table from SAP FuBa was successfull " & SAPResulttable.Rows.Count & " Rows were inserted to table '" & oTablename & "'!")
MsgBox("Create table was successfull! " & vbNewLine & SAPResulttable.Rows.Count & " Rows were inserted to table '" & oTablename & "'!", MsgBoxStyle.Information)
Catch ex As Exception
MsgBox("Unexpected Error in SQL bulkCopy: " & ex.Message, MsgBoxStyle.Critical)
Me.Cursor = Cursors.Default