Imports System.Data.SqlClient
Imports System.Data.SqlDbType
Imports Newtonsoft.Json

Module Module1

    Dim Parameters As New clsParams
    Sub main()
        Parameters.get_params()
        try_get_jsonstring()
    End Sub

    Private Function try_get_jsonstring()
        Dim connection As New SqlConnection(Parameters.Connectionstring_EDOKA)
        Dim scmCmdToExecute As SqlCommand = New SqlCommand()
        Dim dtToReturn As DataTable = New DataTable()
        Dim ds As New DataSet
        Dim sdaAdapter As SqlDataAdapter = New SqlDataAdapter(scmCmdToExecute)
        scmCmdToExecute.CommandText = "dbo.Get_OnBase_Parameters"
        scmCmdToExecute.Parameters.Add("dokumentid", "")

        scmCmdToExecute.CommandType = CommandType.StoredProcedure
        scmCmdToExecute.Connection = connection
        Try
            sdaAdapter.Fill(ds)
            Dim json As String
            json = JsonConvert.SerializeObject(ds, Formatting.Indented)
            Dim file As System.IO.StreamWriter
            file = My.Computer.FileSystem.OpenTextFileWriter("k:\edoka\jsonoutput.text", True)
            file.Write(json)
            file.Close()
            Return dtToReturn
        Catch ex As Exception
        Finally
            scmCmdToExecute.Dispose()
            sdaAdapter.Dispose()
            dtToReturn.Dispose()
        End Try
    End Function
End Module
