?
Solved

Visual Studio 2008 (Visual Basic OR C#) -- Lookup Table w/ TextBoxes

Posted on 2010-01-09
6
Medium Priority
?
939 Views
Last Modified: 2013-11-26
Hi Experts!  <Visual Basic 2008 Newbie here> !

I want to create a very simple (1 page VB2008 form), which connects to an external table, "looks up" values based on a Zip Code ... and populates three(3) textboxes on my form.  Note:  I purchased a TABLE (ZipInfo) from a commercial carrier, which is ALREADY POPULATED with every valid zipcode, city, state and county in the country.

So.. to begin:
1)  I want to create a VB 2008 Form, which will have only four (4) text boxes, labeled as follows: txtZipcode,  txtCity,   txtState,   and   txtCounty.  

2)  I want the user to enter in a 'Zip Code' in the textbox labeled:   'txtZipcode'.  After the
     user presses 'ENTER',

3)  I want my VB2008 form to then execute some code (???) which will:
     a) lookup the matching city, state and county field values, from the Zipcode (ZipInfo) table;
     b) populate each of the three textboxes (labeled txtCity, txtState, txtCounty) on my
         VB2008 form, with the corresponding information from the Zipcode table.

I have ATTACHED a picture of the VB2008 form, I've created so far.

I don't know anything, other then to drag the textboxes from the VB2008  toolbox to a blank form.  I don't understand ADO, or coding or where to put the code to begin with.  I don't know how to reference the connection to the ZipInfo table.  I'm not even certain how to connect properly to the data source.

When I asked this question before, I was given a VB 6 solution, which doesn't appear to work with VB 2008.  

I would really like to know a VB2008 solution and a C# solution, ideally ... so that I can try and understand how making data connections, connecting to the data and populating forms works in Visual Studio 2008.

In conclusion,

I need a 'STEP-BY-STEP' answer, so that I can learn easily.  I'm guessing that there are likely many blog readers who would benefit by your answer(s).

Thanks Everyone!


VB2008-Form.jpg
0
Comment
Question by:DelphiNewb
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
6 Comments
 
LVL 41

Expert Comment

by:guru_sami
ID: 26274455
what database would be that table in?
here is are some basic tutorials on using Ado.net with C#:
http://asp.dotnetheaven.com/howto/doc/adoplus/sqldtreader.aspx
http://www.csharp-station.com/Tutorials/AdoDotNet/Lesson01.aspx
0
 

Author Comment

by:DelphiNewb
ID: 26275984
Hello Guru_Sami --

Thank you very much Guru_Sami for the tutorial links... I am studying them now...

To answer your question, the database I was considering was either SQL Server Express 2008, or...
VistaDB.

Thank you again for the information ... this might provide me enough information.  Reviewing now.

If you come across any additional information, I would appreciate it. --- Thomas
0
 
LVL 83

Accepted Solution

by:
CodeCruiser earned 2000 total points
ID: 26305173
Here is some example code in VB.NET.
Private Sub txtZipCode_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles txtZipCode.KeyPress
        If Asc(e.KeyChar) = 13 Then
            Dim dbcon As New SqlConnection(connectionstring)
            dbcon.Open()
            Dim dbcmd As New SqlCommand
            dbcmd.Connection = dbcon
            dbcmd.CommandText = "Select City, State, County from tblAddresses where zipcode=" & txtZipCode.Text
            Dim dbreader As SqlDataReader = dbcmd.ExecuteReader
            If dbreader.HasRows Then
                dbreader.Read()
                txtCity.Text = dbreader.Item("City")
                txtState.Text = dbreader.Item("State")
                txtCounty.Text = dbreader.Item("County")
            End If
            dbreader.Close()
            dbcmd.Dispose()
            dbcon.Dispose()
        End If
    End Sub

Open in new window

0
NFR key for Veeam Backup for Microsoft Office 365

Veeam is happy to provide a free NFR license (for 1 year, up to 10 users). This license allows for the non‑production use of Veeam Backup for Microsoft Office 365 in your home lab without any feature limitations.

 

Author Comment

by:DelphiNewb
ID: 26333404
I want to thank CodeCruiser very much ... your example was right on, and will work great!
Thank you so much for your clear and complete answer!

CodeCruiser ... you rock!

Thanks --- DelphiNewb
0
 

Author Closing Comment

by:DelphiNewb
ID: 31675018
CodeCruiser's answer was very very helpful.

I am now his or her (CodeCruiser's) fan!
0
 
LVL 83

Expert Comment

by:CodeCruiser
ID: 26334342
Glad to help :-)
0

Featured Post

Veeam Task Manager for Hyper-V

Task Manager for Hyper-V provides critical information that allows you to monitor Hyper-V performance by displaying real-time views of CPU and memory at the individual VM-level, so you can quickly identify which VMs are using host resources.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article will show, step by step, how to integrate R code into a R Sweave document
This article shows how to deploy dynamic backgrounds to computers depending on the aspect ratio of display
This theoretical tutorial explains exceptions, reasons for exceptions, different categories of exception and exception hierarchy.
The viewer will learn additional member functions of the vector class. Specifically, the capacity and swap member functions will be introduced.
Suggested Courses

764 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question