
Imports System.Data
Imports System.IO
Imports System.Data.SqlClient
Imports System.Globalization


Public Class cSqlDb
    Public Shared Function GetNewOpenConnection() As SqlConnection
        Dim cn As New SqlConnection()
        cn.ConnectionString = My.Resources.connStringAdmin
        cn.Open()
        Return cn
    End Function
End Class
Public Class sqlConn
    Public Function getDataSQL(ByVal selectCommand As String) As SqlDataAdapter

        Dim d As New SqlDataAdapter()

        Try
            ' Specify a connection string. Replace the given value with a 
            ' valid connection string for a Northwind SQL Server sample
            ' database accessible to your system.
            '    Dim connectionString As String = "Data Source=DEVELOPER\DEVSQL;Initial Catalog=ADMIN;Integrated Security=false;User ID=sa;Password=BmWr501956;"

            ' Create a new data adapter based on the specified query.
            d = New SqlDataAdapter(selectCommand, My.Resources.connStringAdmin)
            Return d
            ' Resize the DataGridView columns to fit the newly loaded content.

        Catch ex As SqlException
            MessageBox.Show("Der Connection-String kann nicht verarbeitet werden. Wenden Sie sich an den Programmbetreuer.")
        End Try
        Return Nothing
    End Function



    Public Function getDatatableBySql(hSQL As String) As DataTable

        Try
            Dim myTable = New DataTable()
            Using conn As SqlConnection = cSqlDb.GetNewOpenConnection()
                Using cmd As New SqlCommand(hSQL, conn)
                    Dim dr = cmd.ExecuteReader()
                    myTable.Load(dr)
                    myTable.Columns(0).ReadOnly = False
                    dr.Close()
                End Using
                conn.Close()
            End Using

            Return myTable  'While Schleife wird hier verlassen
        Catch ex As Exception
            Dim antwort As MsgBoxResult = MsgBox(ex.Message, CType(MsgBoxStyle.RetryCancel + MsgBoxStyle.Exclamation, MsgBoxStyle),
                                          "Problem in Function 'AnzeigeTabelle'")
            If antwort <> MsgBoxResult.Retry Then
                'Programm wird beendet
                MsgBox(System.Reflection.MethodInfo.GetCurrentMethod.Name & ": Programm wird aufgrund eines kritischen Problems beendet.", vbInformation)
                Environment.Exit(0)
            End If
        End Try
        
        Return Nothing

    End Function
End Class
