128 lines
5.6 KiB
VB.net
128 lines
5.6 KiB
VB.net
Public Class ClassDatabase
|
|
Private Shared SQLSERVERConnectionString As String
|
|
Private Shared OracleConnectionString As String
|
|
Public Shared Function Init()
|
|
Try
|
|
SQLSERVERConnectionString = My.Settings.ConfigConnectionString
|
|
Dim SQLconnect As New SqlClient.SqlConnection
|
|
SQLconnect.ConnectionString = SQLSERVERConnectionString
|
|
SQLconnect.Open()
|
|
SQLconnect.Close()
|
|
Return True
|
|
Catch ex As Exception
|
|
MsgBox("Fehler bei Database Init: " & ex.Message, MsgBoxStyle.Critical)
|
|
Return False
|
|
End Try
|
|
End Function
|
|
|
|
Public Shared Function Return_Datatable(Select_anweisung As String, Optional userInput As Boolean = False)
|
|
Try
|
|
Dim SQLconnect As New SqlClient.SqlConnection
|
|
Dim SQLcommand As SqlClient.SqlCommand
|
|
SQLconnect.ConnectionString = SQLSERVERConnectionString
|
|
SQLconnect.Open()
|
|
SQLcommand = SQLconnect.CreateCommand
|
|
SQLcommand.CommandText = Select_anweisung
|
|
|
|
Dim adapter1 As SqlClient.SqlDataAdapter = New SqlClient.SqlDataAdapter(SQLcommand)
|
|
Dim dt As DataTable = New DataTable()
|
|
adapter1.Fill(dt)
|
|
SQLconnect.Close()
|
|
Return dt
|
|
Catch ex As Exception
|
|
If userInput = True Then
|
|
MsgBox("Error in Return Datatable - Error-Message:" & vbNewLine & ex.Message & vbNewLine & "SQL-Command:" & vbNewLine & Select_anweisung, MsgBoxStyle.Critical)
|
|
End If
|
|
MsgBox("Fehler bei Return_Datatable: " & ex.Message, MsgBoxStyle.Critical)
|
|
Return Nothing
|
|
End Try
|
|
End Function
|
|
Public Shared Function Return_Datatable_CS(Select_anweisung As String, ConString As String, Optional userInput As Boolean = False)
|
|
Try
|
|
Dim SQLconnect As New SqlClient.SqlConnection
|
|
Dim SQLcommand As SqlClient.SqlCommand
|
|
SQLconnect.ConnectionString = ConString
|
|
SQLconnect.Open()
|
|
SQLcommand = SQLconnect.CreateCommand
|
|
SQLcommand.CommandText = Select_anweisung
|
|
|
|
Dim adapter1 As SqlClient.SqlDataAdapter = New SqlClient.SqlDataAdapter(SQLcommand)
|
|
Dim dt As DataTable = New DataTable()
|
|
adapter1.Fill(dt)
|
|
SQLconnect.Close()
|
|
Return dt
|
|
Catch ex As Exception
|
|
If userInput = True Then
|
|
MsgBox("Error in Return_Datatable_CS - Error-Message:" & vbNewLine & ex.Message & vbNewLine & "SQL-Command:" & vbNewLine & Select_anweisung, MsgBoxStyle.Critical)
|
|
End If
|
|
MsgBox("Fehler bei Return_Datatable_CS: " & ex.Message, MsgBoxStyle.Critical)
|
|
Return Nothing
|
|
End Try
|
|
End Function
|
|
Public Shared Function Execute_non_Query(ExecuteCMD As String, Optional userInput As Boolean = False)
|
|
Try
|
|
Dim SQLconnect As New SqlClient.SqlConnection
|
|
Dim SQLcommand As SqlClient.SqlCommand
|
|
SQLconnect.ConnectionString = SQLSERVERConnectionString
|
|
SQLconnect.Open()
|
|
SQLcommand = SQLconnect.CreateCommand
|
|
'Update Last Created Record in Foo
|
|
SQLcommand.CommandText = ExecuteCMD
|
|
SQLcommand.ExecuteNonQuery()
|
|
SQLcommand.Dispose()
|
|
SQLconnect.Close()
|
|
Return True
|
|
Catch ex As Exception
|
|
If userInput = True Then
|
|
MsgBox("Error in Execute non query - Error-Message:" & vbNewLine & ex.Message & vbNewLine & "SQL-Command:" & vbNewLine & ExecuteCMD, MsgBoxStyle.Critical)
|
|
End If
|
|
MsgBox("Fehler bei Execute_non_Query: " & ex.Message, MsgBoxStyle.Critical)
|
|
Return False
|
|
End Try
|
|
End Function
|
|
Public Shared Function Execute_Scalar(cmdscalar As String, Optional Userinput As Boolean = False)
|
|
Dim result
|
|
Try
|
|
Dim SQLconnect As New SqlClient.SqlConnection
|
|
Dim SQLcommand As SqlClient.SqlCommand
|
|
SQLconnect.ConnectionString = SQLSERVERConnectionString
|
|
SQLconnect.Open()
|
|
SQLcommand = SQLconnect.CreateCommand
|
|
'Update Last Created Record in Foo
|
|
SQLcommand.CommandText = cmdscalar
|
|
result = SQLcommand.ExecuteScalar()
|
|
SQLcommand.Dispose()
|
|
SQLconnect.Close()
|
|
Return result
|
|
Catch ex As Exception
|
|
If Userinput = True Then
|
|
MsgBox("Fehler bei Execute_Scalar: " & ex.Message & vbNewLine & vbNewLine & cmdscalar, MsgBoxStyle.Critical)
|
|
End If
|
|
MsgBox("Fehler bei Execute_Scalar: " & ex.Message, MsgBoxStyle.Critical)
|
|
Return Nothing
|
|
End Try
|
|
End Function
|
|
Public Shared Function Execute_Scalar_CS(cmdscalar As String, cs As String, Optional Userinput As Boolean = False)
|
|
Dim result
|
|
Try
|
|
Dim SQLconnect As New SqlClient.SqlConnection
|
|
Dim SQLcommand As SqlClient.SqlCommand
|
|
SQLconnect.ConnectionString = cs
|
|
SQLconnect.Open()
|
|
SQLcommand = SQLconnect.CreateCommand
|
|
'Update Last Created Record in Foo
|
|
SQLcommand.CommandText = cmdscalar
|
|
result = SQLcommand.ExecuteScalar()
|
|
SQLcommand.Dispose()
|
|
SQLconnect.Close()
|
|
Return result
|
|
Catch ex As Exception
|
|
If Userinput = True Then
|
|
MsgBox("Fehler bei Execute_Scalar_CS: " & ex.Message & vbNewLine & vbNewLine & cmdscalar, MsgBoxStyle.Critical)
|
|
End If
|
|
MsgBox("Fehler bei Execute_Scalar_CS: " & ex.Message, MsgBoxStyle.Critical)
|
|
Return Nothing
|
|
End Try
|
|
End Function
|
|
End Class
|