Imports System.Data.SqlClient

Public Class cSQL

    Public Shared Sub SQL2DS(ByRef selector As String, ByRef ds As DataSet)
        Dim con As New SqlConnection
        Dim cmd As New SqlCommand
        con.ConnectionString = cListe.DBConnectionString
        cmd.Connection = con

        Dim dataadapter As New SqlDataAdapter(selector, con)
        con.Open()
        dataadapter.Fill(ds)
        con.Close()
    End Sub

    Public Shared Sub UpdateSQL(ByRef table As String, ByRef values As String, ByRef where As String)
        Dim con As New SqlConnection
        Dim cmd As New SqlCommand
        con.ConnectionString = cListe.DBConnectionString
        cmd.Connection = con

        con.Open()
        cmd.CommandText = "UPDATE " & table & " SET " & values & " WHERE " & where & ""
        cmd.ExecuteNonQuery()
        con.Close()
    End Sub

    Public Shared Sub InsertSQL(ByRef table As String, ByRef insert As String)
        Dim con As New SqlConnection
        Dim cmd As New SqlCommand
        con.ConnectionString = cListe.DBConnectionString
        cmd.Connection = con

        con.Open()
        cmd.CommandText = "INSERT INTO " & table & " " & insert & ""
        cmd.ExecuteNonQuery()
        con.Close()
    End Sub

    Public Shared Sub DeleteFromSQL(ByRef table As String, ByRef where As String)
        Dim con As New SqlConnection
        Dim cmd As New SqlCommand
        con.ConnectionString = cListe.DBConnectionString
        cmd.Connection = con

        con.Open()
        cmd.CommandText = "DELETE " & table & "  WHERE " & where & ""
        cmd.ExecuteNonQuery()
        con.Close()
    End Sub

    Public Shared Sub SqlQuery(ByRef query As String)
        Dim con As New SqlConnection
        Dim cmd As New SqlCommand
        con.ConnectionString = cListe.DBConnectionString
        cmd.Connection = con

        con.Open()
        cmd.CommandText = query
        cmd.ExecuteNonQuery()
        con.Close()
    End Sub


End Class



Public Class SQLTools

    Public Shared Function hochkomma(textin As String)
        Dim textout As String = textin.Replace("'", "''")
        Return (textout)
    End Function

    Public Shared Function DBNull2emptyString(totest As Object)
        If IsDBNull(totest) Then
            Return ""
        Else
            Return totest
        End If
    End Function

    Public Shared Function CheckIfExist(sqlstring As String)
        Dim ds As New DataSet
        cSQL.SQL2DS(sqlstring, ds)
        If ds.Tables(0).Rows.Count > 0 Then
            Return True
        Else
            Return False
        End If
    End Function

    Public Shared Function auf49kuerzen(Str As String)
        If Str.Length >= 50 Then
            Return Str.Substring(0, 49)
        Else
            Return Str
        End If
    End Function

End Class



Public Class SQLVariable
    Private Text, Value As String
    Private prim As Boolean

    Public Sub New(ByVal btext As String, ByVal bvalue As String, Optional bprim As Boolean = False)
        Me.Value = bvalue
        Me.Text = btext

    End Sub

    Public ReadOnly Property SQLText() As String
        Get
            Return Text
        End Get
    End Property

    Public ReadOnly Property SQLValue() As Object
        Get
            Return Value
        End Get
    End Property




End Class
