Digital Data - Marlon Schreiber f2e7c6fc6b MS
2017-11-27 14:27:40 +01:00

81 lines
3.1 KiB
VB.net

Public Class ClassDatabase
Private Shared connectionString As String
Public Shared Function Init()
Try
connectionString = MyConnectionString
Dim SQLconnect As New SqlClient.SqlConnection
SQLconnect.ConnectionString = connectionString
SQLconnect.Open()
SQLconnect.Close()
Return True
Catch ex As Exception
ClassLogger.Add("Fehler bei DatabaseInit: " & ex.Message, True)
Return False
End Try
End Function
Public Shared Function Return_Datatable(Select_anweisung As String)
Try
Dim SQLconnect As New SqlClient.SqlConnection
Dim SQLcommand As SqlClient.SqlCommand
SQLconnect.ConnectionString = connectionString
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
ClassLogger.Add("Fehler bei Return_Datatable: " & ex.Message, True)
ClassLogger.Add("SQL: " & Select_anweisung, False)
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 = connectionString
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("Fehler bei Execute_non_Query: " & ex.Message, MsgBoxStyle.Critical)
End If
ClassLogger.Add("Fehler bei Execute_non_Query: " & ex.Message, True)
ClassLogger.Add("SQL: " & ExecuteCMD, False)
Return False
End Try
End Function
Public Shared Function Execute_Scalar(cmdscalar As String)
Dim result
Try
Dim SQLconnect As New SqlClient.SqlConnection
Dim SQLcommand As SqlClient.SqlCommand
SQLconnect.ConnectionString = connectionString
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
ClassLogger.Add("Fehler bei Execute_Scalar: " & ex.Message, True)
ClassLogger.Add("SQL: " & cmdscalar, False)
Return Nothing
End Try
End Function
End Class