Visual Studio Upgrade Question 2003-2005 SQLDATAREADER

Posted on 2007-07-28
Last Modified: 2013-11-26
Please ignore the open questions I have outstanding - those I had to solve on my own
I upgraded from 2003 to 2005.
Converting code is difficult I am looking for some help.

This code was created in 2003 version of VS - Please help me convert by using 2005 methods

This code is executed on the ZipCode field textchanged event
        Dim dr As SqlDataReader
        dr = SqlCommand2.ExecuteReader()
        While dr.Read()
            If (dr("ZIPCODE")) = Zip.Text Then
                'fldZip.Text = dr("Zipcode")
                City.Text = UCase(dr("City"))
                State.Text = UCase(dr("State"))
                'fldCity.Text = ""
                'fldState.Text = ""
            End If
        End While
Question by:DalerTheWhaler
    LVL 96

    Accepted Solution

    Using connection As New SqlConnection(connectionString)
       Using command As New SqlCommand(commandText, connection)
            Using reader As SqlDataReader = command.ExecuteReader()
                Dim table As New DataTable()
                Dim row As DataRow = table.Rows(0)
                City.Text = row("City").ToString().ToUpper()
                State.State = row("State").ToString().ToUpper()
            End Using
       End Using
    End Using


    Author Comment

    I will give it a shot right now...thanks for responding TheLearnedOne

    Author Comment

    I have a couple of problems with the code'

    Using connection As New SqlConnection(connectionString)
    [connectionstring] not declared - I assume that I enter my own connstr here yes?

    Using command As New SqlCommand(commandText, connection)
    [commandtext] not declared - that I have no clue

    Also....How can I learn this code?  Any good references can u suggest?
    LVL 96

    Expert Comment

    by:Bob Learned
    1) You need a connection string, from where ever that you get it.

    2) You need a select statement:  Select * From Table1

    3) I don't have any specific references for ADO.NET, but you could use Google to look for ADO.NET tutorials.


    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    How your wiki can always stay up-to-date

    Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
    - Increase transparency
    - Onboard new hires faster
    - Access from mobile/offline

    Suggested Solutions

    In my previous article ( we saw the basics of serialization and how types/objects can be serialized to Binary format. In this blog we wi…
    Wouldn’t it be nice if you could test whether an element is contained in an array by using a Contains method just like the one available on List objects? Wouldn’t it be good if you could write code like this? (CODE) In .NET 3.5, this is possible…
    how to add IIS SMTP to handle application/Scanner relays into office 365.
    This video is in connection to the article "The case of a missing mobile phone (". It will help one to understand clearly the steps to track a lost android phone.

    737 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

    Need Help in Real-Time?

    Connect with top rated Experts

    20 Experts available now in Live!

    Get 1:1 Help Now