Click here to Skip to main content
15,885,931 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

Thanks
Posted

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:
http://www.webservicex.net/uszip.asmx[^],
http://www.webservicex.net/uszip.asmx?WSDL[^].

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:
https://msdn.microsoft.com/en-us/library/dd355316.aspx[^],
https://msdn.microsoft.com/en-us/library/d2s8y7bs%28VS.100%29.aspx[^],
http://www.sitepoint.com/net-web-services-5-steps[^].

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: http://stackoverflow.com/questions/13407156/how-to-consume-a-webservice-using-wsdl-files-in-c-sharp[^].

—SA
 
Share this answer
 
v2
Comments
sudevsu 13-Aug-15 14:33pm    
Thank you
Sergey Alexandrovich Kryukov 13-Aug-15 16:40pm    
You are welcome.
—SA
So here is my solution...

VB
Dim ds As New DataSet()
       Dim url As String = "http://maps.google.com/maps/api/geocode/xml?address=" + 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)
               ds.ReadXml(reader)
               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
 
Share this answer
 

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