<%@ Page Language="VB" ContentType="text/xml" %>
<%@ import Namespace="System.Xml" %>
<%@ import Namespace="System.Text" %>
<%@ import Namespace="System.Data" %>
<%@ import Namespace="System.Data.OleDb" %>
<script runat="server">

    Sub Page_Load(sender As Object, e As EventArgs)
      Dim strPostalCode As String = Request.Params("p")
      Dim writer As New XmlTextWriter(Response.OutputStream, Encoding.UTF8)
      Dim dr As OleDbDataReader = GetAddressByPostalCode(strPostalCode)
      Dim strKen As String = ""
      Dim strCity As String = ""
      Dim strTown As String = ""
      Dim strRc As String = "0"
    
      If dr.Read Then
        strRc = "1"
        strKen = dr("Ken")
        strCity = dr("City")
        strTown = dr("Town")
      End If
      dr.Close
    
      writer.WriteStartDocument()
        writer.WriteStartElement("response")
          writer.WriteElementString("rc", strRc)
          writer.WriteElementString("ken", strKen)
          writer.WriteElementString("city", strCity)
          writer.WriteElementString("town", strTown)
        writer.WriteEndElement()
      writer.WriteEndDocument()
      writer.Close()
    End Sub
    
    Function GetAddressByPostalCode(ByVal strPostalCode As String) As OleDbDataReader
      Dim strSQL As String = "Select Top 1 * From tblPostalCode Where Code=?"
      Dim strConnectionString As String = _
        String.Format("PROVIDER=Microsoft.Jet.OLEDB.4.0;DATA Source={0}", _
        Server.MapPath("webdb/PostalCode.mdb"))
      Dim con As New OleDbConnection(strConnectionString)
      Dim cmd As New OleDbCommand(strSQL, con)
    
      cmd.Parameters.Add("Code", strPostalCode)
      con.Open()
      Dim dr As OleDbDataReader = cmd.ExecuteReader(CommandBehavior.CloseConnection)
      Return dr
    End Function

</script>
