Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. Address

Address

Scheduled Pinned Locked Moved C#
databasehelp
6 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • B Offline
    B Offline
    boiDev
    wrote on last edited by
    #1

    Hi .. Everyone Im trying to a simple address lookup using winform. What im trying to do is have a text box were a user can type in their PostCode/zip code and it will do a simple database(Sql) lookup but you do not have to type in your full postcode/ zip i can b just the first few characters and it still should find the full address information .. Can any one help me with this because im stuck on this

    L 1 Reply Last reply
    0
    • B boiDev

      Hi .. Everyone Im trying to a simple address lookup using winform. What im trying to do is have a text box were a user can type in their PostCode/zip code and it will do a simple database(Sql) lookup but you do not have to type in your full postcode/ zip i can b just the first few characters and it still should find the full address information .. Can any one help me with this because im stuck on this

      L Offline
      L Offline
      Lost User
      wrote on last edited by
      #2

      Well did you try anything yet? Are you creating this database? Let's see some code, what do you have done so far, which part are you specifically stuck on?

      B 1 Reply Last reply
      0
      • L Lost User

        Well did you try anything yet? Are you creating this database? Let's see some code, what do you have done so far, which part are you specifically stuck on?

        B Offline
        B Offline
        boiDev
        wrote on last edited by
        #3

        using System; using System.Collections.Generic; using System.Collections.Specialized; using System.ComponentModel; using System.Data; using System.Data.SqlClient; using System.Drawing; using System.Text; using System.Windows.Forms; namespace AddressFinder { public partial class AddressSelecter : Form { private static readonly object EventClose = new object(); public event EventHandler OnClose { add { Events.AddHandler(EventClose,value); } remove { Events.RemoveHandler(EventClose,value); } } public virtual void OnCloseEvent(EventArgs e) { EventHandler handler = (EventHandler) Events[EventClose]; if(handler!=null) { handler(this, e); } } public AddressSelecter() { InitializeComponent(); } private string buildingNo; public string BuildingNo { get { return buildingNo; } set { buildingNo = value; } } private string street; public string Street { get { return street; } set { street = value; } } private string city; public string City { get { return city; } set { city = value; } } private string country; public string Country { get { return country; } set { country = value; } } public string PostCode { get { return txtPostCode.Text; } set { txtPostCode.Text = value; } } private void button1_Click(object sender, EventArgs e) { SqlCommand cmd = new SqlCommand(@"select b.buildingId, b.buildingname, s.streetname, c.cityname from zipcode z inner join city c on z.CityID = c.CityID inner join building b on z.zipcodeid = b.zipcodeid inner join street s on z.zipcodeid

        L 1 Reply Last reply
        0
        • B boiDev

          using System; using System.Collections.Generic; using System.Collections.Specialized; using System.ComponentModel; using System.Data; using System.Data.SqlClient; using System.Drawing; using System.Text; using System.Windows.Forms; namespace AddressFinder { public partial class AddressSelecter : Form { private static readonly object EventClose = new object(); public event EventHandler OnClose { add { Events.AddHandler(EventClose,value); } remove { Events.RemoveHandler(EventClose,value); } } public virtual void OnCloseEvent(EventArgs e) { EventHandler handler = (EventHandler) Events[EventClose]; if(handler!=null) { handler(this, e); } } public AddressSelecter() { InitializeComponent(); } private string buildingNo; public string BuildingNo { get { return buildingNo; } set { buildingNo = value; } } private string street; public string Street { get { return street; } set { street = value; } } private string city; public string City { get { return city; } set { city = value; } } private string country; public string Country { get { return country; } set { country = value; } } public string PostCode { get { return txtPostCode.Text; } set { txtPostCode.Text = value; } } private void button1_Click(object sender, EventArgs e) { SqlCommand cmd = new SqlCommand(@"select b.buildingId, b.buildingname, s.streetname, c.cityname from zipcode z inner join city c on z.CityID = c.CityID inner join building b on z.zipcodeid = b.zipcodeid inner join street s on z.zipcodeid

          L Offline
          L Offline
          Lost User
          wrote on last edited by
          #4

          Use autocomplete on your textbox and bind your postal codes as a datasource, or you can use wildcards for your sql statement albeit you will get multiple results if a search overlaps 2 or more results. I would use wildcards.

          B 1 Reply Last reply
          0
          • L Lost User

            Use autocomplete on your textbox and bind your postal codes as a datasource, or you can use wildcards for your sql statement albeit you will get multiple results if a search overlaps 2 or more results. I would use wildcards.

            B Offline
            B Offline
            boiDev
            wrote on last edited by
            #5

            Im sorry to bother you .. but do you think that looking at my code is it very good or is no that good .. becuase i have only just started C# 2 weeks ago and i tought my self .. I dont know how to use wildcard .. if they is an example i can follow i would be happy :-)

            L 1 Reply Last reply
            0
            • B boiDev

              Im sorry to bother you .. but do you think that looking at my code is it very good or is no that good .. becuase i have only just started C# 2 weeks ago and i tought my self .. I dont know how to use wildcard .. if they is an example i can follow i would be happy :-)

              L Offline
              L Offline
              Lost User
              wrote on last edited by
              #6

              If youre using access the wildcard is * or if you are using mssql or mysql the wildcard is % For instance you have a table called names with Lesley, Leyla and mike if you do select * from names where name LIKE e% you will get results of Lesley and Leyla. You are off to a good start for 2 weeks, look up on good practices and naming conventions. Edit; its no bother, you are making an effort and thats what counts.

              1 Reply Last reply
              0
              Reply
              • Reply as topic
              Log in to reply
              • Oldest to Newest
              • Newest to Oldest
              • Most Votes


              • Login

              • Don't have an account? Register

              • Login or register to search.
              • First post
                Last post
              0
              • Categories
              • Recent
              • Tags
              • Popular
              • World
              • Users
              • Groups