Jump to content

madsovenielsen

Members
  • Posts

    142
  • Joined

  • Last visited

Posts posted by madsovenielsen

  1. HelloI know this is a total newb question, but i have the following SQL:

    SELECT FagNavn, adgangskrav, Ugedag, holdId, fagKode, CONVERT(CHAR(10), StartDato, 105) AS startDate, CONVERT(CHAR(10), slutDato, 105) AS endDate, afdeling, link, navn, deltagerBetaling, bt, niveau, Case When Ugedag = 'Mandag' Then frakl + ' - ' + tilkl Else '' End AS startSlutMandag, Case When Ugedag = 'Tirsdag' Thenfrakl + ' - ' + tilkl Else '' End AS startSlutTirsdag, Case When Ugedag = 'Onsdag' Thenfrakl + ' - ' + tilkl Else '' End AS startSlutOnsdag, Case When Ugedag = 'Torsdag' Then frakl + ' - ' + tilkl Else '' End AS startSlutTorsdag, Case When Ugedag = 'Fredag' Thenfrakl + ' - ' + tilkl Else '' End AS startSlutFredag FROM [VisWebHoldSkema] ORDER BY afdeling

    This is giving me records with each weekday (Ugedag) like this:

    +--------+-----------------+------------------+-----------------+------------------+-----+ | holdId | startSlutMandag | startSlutTirsdag | startSlutOnsdag | startSlutTorsdag | ... |+--------+-----------------+------------------+-----------------+------------------+-----+| 1587b1 | 09:00 - 15:30   |                  |                 |                  | ... |+--------+-----------------+------------------+-----------------+------------------+-----+| 1587b1 |                 | 08:00 - 15:00    |                 |                  | ... |+--------+-----------------+------------------+-----------------+------------------+-----+| 1587b1 |                 |                  | 08:30 - 18:00   |                  | ... |+--------+-----------------+------------------+-----------------+------------------+-----+| 1587b1 |                 |                  |                 | 15:00 - 04:00    | ... |+--------+-----------------+------------------+-----------------+------------------+-----+

    But i need the days to be in the same record, like this:

    +--------+-----------------+------------------+-----------------+------------------+-----+| holdId | startSlutMandag | startSlutTirsdag | startSlutOnsdag | startSlutTorsdag | ... |+--------+-----------------+------------------+-----------------+------------------+-----+| 1587b1 | 09:00 - 15:30   | 08:00 - 15:00    | 08:30 - 18:00   | 15:00 - 04:00    | ... |+--------+-----------------+------------------+-----------------+------------------+-----+

    Some sample data from the db:

     

     

    Any ideas?

    data.txt

  2. Hello I need to delete array items and compact the array (multidimentional). I have not been able to find any "build in" function for this in VBScript. I would like to be able to "delete" array items and compact the remaining items so there is no gaps. Array example:

    Dim example(4,20) example(0,0) = "54HG12-KLD"example(1,0) = "Thingamabob"example(2,0) = "Good for long hikes."example(3,0) = "599" example(0,1) = "54HG12-GHJ"example(1,1) = "Thingamabob"example(2,1) = "Good for short hikes."example(3,1) = "499"...

    Does anyone have a function er code snippet, or maybe some good advice on writing a function to tackle this. Kind regards Mads

  3. Hello

    Imports System.Web.Script.SerializationImports System.Data.SqlClientPublic Class jsonTest	Dim objSQLConnection As SqlConnection	Dim objSQLCommand As SqlCommand	Dim objSQLDataReader As SqlDataReader	Dim objJSONStringBuilder As StringBuilder	Public Function returnJson() As String		Dim col1 As New ArrayList		Dim col2 As New ArrayList		objJSONStringBuilder = New StringBuilder()		Dim connString As String = System.Configuration.ConfigurationManager.ConnectionStrings("VUCConnectionString").ConnectionString		objSQLConnection = New SqlConnection(System.Configuration.ConfigurationManager.AppSettings(connString))		objSQLCommand = New SqlCommand("select col1, col2 from table1", objSQLConnection)		objSQLCommand.Connection.Open()		objSQLDataReader = objSQLCommand.ExecuteReader()		While objSQLDataReader.Read()			col1.Add(objSQLDataReader("col1"))		End While		objSQLDataReader.Close()		objSQLCommand.Connection.Close()		Dim serializer As New JavaScriptSerializer()		Dim arrayJson As String = serializer.Serialize(col1)		Return arrayJson	End FunctionEnd ClassPublic Class wwwroot_Default	Inherits System.Web.UI.Page	Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load		Dim jsontest As New jsonTest()		Dim test As String = jsontest.returnJson()		jsonOutput.Text = test	End SubEnd Class

    I am trying to return JSON data from the database, this is _so_ easy with PHP, but i am forced to use ASP.NET I am gettting the following error from the code above:

    The ConnectionString property has not been initialized.Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.Exception Details: System.InvalidOperationException: The ConnectionString property has not been initialized.Source Error:Line 22:		 objSQLCommand = New SqlCommand("select col1, col2 from table1", objSQLConnection)Line 23:Line 24:		 objSQLCommand.Connection.Open()Line 25:		 objSQLDataReader = objSQLCommand.ExecuteReader()Line 26: Source File: [url="file://\WebfilefswebsitesDATAPOOL006u12ekgqwwwrootDefault.aspx.vb"]\\Webfilefs\websites\DATAPOOL006\u12ekgq\wwwroot\Default.aspx.vb[/url]    Line: 24

    Everything seems fine in the editor, and i know the connection string is working, at least on other sites. Any suggestions are most welcome, and please, if there is an easier way of doing this, ala PHP, please enlighten me. Kind regards Mads Nielsen

×
×
  • Create New...