Click here to Skip to main content
15,037,388 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Hello Experts,

Is there any way that I can auto fill City and State with Zip code ?

I wanted to use something really simple.

I have seen some results in google where most of them were with AJAX calls, which we don't want to do it.

I would appreciate tutorials/ code/ referral link.

I am also open to suggestions


Apparently, you just need a database of cities/towns by zip codes (but how can you update it when changes are done?) or use one or another Web service (or even a site) to fetch this data. For example:[^],[^].

As you can see, this is both a "regular" Web site, and a Web service. As you have WSDL, this won't be a problem:[^],[^],[^].

Not all services work like that. In such cases, read their API documentation. You can work with any Web resource on low level using the class HttpWebRequest.

See also:[^].

sudevsu 13-Aug-15 14:33pm
Thank you
Sergey Alexandrovich Kryukov 13-Aug-15 16:40pm
You are welcome.
So here is my solution...

Dim ds As New DataSet()
       Dim url As String = "" + txtZip.Text + "&sensor=false"
       Dim request As System.Net.WebRequest = System.Net.WebRequest.Create(url)
       Using response As System.Net.WebResponse = DirectCast(request.GetResponse(), System.Net.HttpWebResponse)
           Using reader As New System.IO.StreamReader(response.GetResponseStream(), Encoding.UTF8)
               Dim dt As DataTable = ds.Tables("result")
               Dim strspliaddress = dt.Rows(0)("formatted_Address").ToString().Split(",")
               txtcity.Text = strspliaddress(0)
txtState.Text= strspliaddress(1)'Something like this

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900