how to convert this PHP code to asp.net?

Last post 08-23-2009 3:59 PM by tartuffe2. 3 replies.

Sort Posts:

  • how to convert this PHP code to asp.net?

    08-23-2009, 4:52 AM
    • Member
      144 point Member
    • tartuffe2
    • Member since 06-28-2006, 6:15 AM
    • Posts 433

    Hi,

    The file index.aspx contains a javascript tag which refers to another aspx file (test.aspx).
    The 'test.aspx' file must fetch data from a database, put the data in a hashtable and finally create an javascript object with the hashtable.
    I can do everything except creating a javascript object. I have the solution in PHP, but cannot convert it in asp.net code.

    Here the code:


    index.aspx
    ----------
    <%@ Page Language="VB" %>

    <html>
    <head></head>
    <body>
    <form ID="form1" runat="server" />
    ...
    ...
    </form>
    </body>
    <script type="text/javascript" src="scripts/test.aspx"></script>
    </html>

    ---------------------------------------------------

    test.aspx
    ---------
    <%@ Page Language="VB" %>
    <%@ Import Namespace="System.Data.SqlClient" %>
    <%@ Import Namespace="System.Collections.Generic" %>

    <script runat="server">
        Sub page_load()

    Response.AddHeader("Content-Type", "text/javascript")

    Dim comd As SqlCommand
    Dim sql As String
    Dim myhash = New Hashtable()

    'here the records are fetched from the database and put in the hashtable
    'i didn't put the whole code to keep it simple but this works
    Using mConnection As New SqlConnection(param.ConnectionString)
    mConnection.Open()
    sql = "select nm from mytable"
    ...
    If dtreader.HasRows Then
                    While dtreader.Read()
                    nm = dtreader.GetString(0)
      if nm="1" then
                        myhash.Add(nm, "yes")
      else
          myhash.Add(nm, "no")
                    End While
    End If
    dtreader.Close()
    End Using


    'now i need to create an javascript object using the hashtable
    'this PHP code: $myhash is the associative array equivalent to the hashtable

    print("var mystat = new Object();\n");
     foreach ($myhash as $name => $value)
     {
      print("mystat.$name = '$value';\n");
     }

    End Sub
    </script>

    -------------------------------------
    I know how to get the keys and values of a hashtable in asp.net, but my problem is: how to do the same as the PHP code?

    Dim objKey As Object
    Dim objValue As Object

    For Each objKey In locatiedata.Keys
    objValue = locatiedata.Item(objKey)
    Response.Write("PCstatusobjKey.ToString & " : " & objValue.ToString & "<br>")
    Next objKey


    Thanks
    Tartuffe

     

     

  • Re: how to convert this PHP code to asp.net?

    08-23-2009, 11:57 AM
    • Member
      49 point Member
    • bhmlt
    • Member since 05-25-2009, 4:40 AM
    • Posts 64
  • Re: how to convert this PHP code to asp.net?

    08-23-2009, 12:40 PM
    • Contributor
      2,386 point Contributor
    • lohith.bn
    • Member since 08-03-2009, 10:14 AM
    • Bangalore
    • Posts 403
  • Re: how to convert this PHP code to asp.net?

    08-23-2009, 3:59 PM
    • Member
      144 point Member
    • tartuffe2
    • Member since 06-28-2006, 6:15 AM
    • Posts 433

     thanks, but instead of reading a lot about migration, downloading software etc ... is it not possible just to convert this code into vb.net/asp.net?

    'now i need to create an javascript object using the hashtable
    'this PHP code: $myhash is the associative array equivalent to the hashtable

    print("var mystat = new Object();\n");
     foreach ($myhash as $name => $value)
     {
      print("mystat.$name = '$value';\n");
     }

Page 1 of 1 (4 items)