locked
SENDING JSON CONVERTED LIST OF STATES FROM SERVER TO CLIENT(AJAX) RRS feed

  • Question

  • User-1409441476 posted

    CAN YOU HELP ME WITH THIS

           NEED TO DECLARE STATELIST BEFORE USING STATEMENT

           STATELIST.Add(STATE)

          HOW DO I DO IT  AND ALSO CAN YOU IDENTIFY ANY OTHER PROBLEMS IN THE SYNTAX AND LOGIC OF THE

          PROGRAM

     

    <%@ Page Language="VB" %>

    <%@ Import NAMESPACE="system.data" %>

    <%@ Import NAMESPACE="system.data.sqlclient" %>

    <%@ Import Namespace="system.Runtime.Serialization.Json.DataContractJsonSerializer" %>

    <%@ Import Namespace="System.IO" %>

    <%@ Import Namespace="System" %>

     

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

     

    <script runat="server">

        Sub Page_Load(Object sender, EventArgs e)

            Dim CONSTRING As String

            CONSTRING = " ServerName=localhost ; DatabaseName=REGGAEDBF, uid=BOBBY   ; pwd=BOBBY"

            Dim CONNECTION As New SqlConnection(CONSTRING)

            CONNECTION.Open()

            Dim SQLSTATES As String

            SQLSTATES = " SELECT * FROM STATEFIL "

            SQLSTATES = SQLSTATES & " WHERE COUNTRYCOD=" & Session.Item("COUNTRYCOD")

            Dim FSTATES As New SqlDataAdapter(SQLSTATES, CONNECTION)

            <st1:place><st1:placename>Dim</st1:placename> <st1:placetype>STATE</st1:placetype></st1:place> = New STATES()

            Dim DTSTATES as New DataTable("STATES")

            DTSTATES.Columns.Add("STATECOD", GetType(Integer))

            DTSTATES.Columns.Add("STATENAM", GetType(String))

            FSTATES.Fill(DTSTATES, "STATES")

            Dim row As DataRow

            Dim column As DataColumn

            For Each row In DTSTATES.Rows

                For Each column In DTSTATES.Columns

                    If column = "STATECOD" Then

                        STATE.STATECOD = row(column)

                    End If

                    If column = "STATENAM" Then

                        STATE.STATENAM = row(column)

                    End If

                Next

                STATELIST.Add(STATE)

            Next

           

            Dim stream As New MemoryStream

            Dim serializer As DataContractJsonSerializer(GetType(STATES))

            serializer.WriteObject(stream, STATELIST)

            stream.Position = 0

            Dim INPUT As New StreamReader(stream)

            Response.Write(INPUT.ReadToEnd)

         End Sub

     </script>

     

     

    Wednesday, April 25, 2012 3:04 PM

All replies

  • User1869050296 posted

    use json.net serializer from object to json

    Wednesday, July 27, 2016 3:45 AM