• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 215
  • Last Modified:

Visual Studio Upgrade Question 2003-2005 SQLDATAREADER

Please ignore the open questions I have outstanding - those I had to solve on my own
I upgraded from VS.net 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
        SqlConnection1.Open()
        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"))
            Else
                'fldCity.Text = ""
                'fldState.Text = ""
            End If
        End While
        dr.Close()
        SqlConnection1.Close()
0
Dale Massicotte
Asked:
Dale Massicotte
  • 2
  • 2
1 Solution
 
Bob LearnedCommented:
Using connection As New SqlConnection(connectionString)
   connection.Open()
   Using command As New SqlCommand(commandText, connection)
        Using reader As SqlDataReader = command.ExecuteReader()
            Dim table As New DataTable()
            table.Load(reader)
            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

Bob
0
 
Dale MassicotteAuthor Commented:
I will give it a shot right now...thanks for responding TheLearnedOne
0
 
Dale MassicotteAuthor Commented:
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?
0
 
Bob LearnedCommented:
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.

http://samples.gotdotnet.com/quickstart/howto/doc/adoplus/ADOPlusOverview.aspx

Bob
0

Featured Post

Get your Disaster Recovery as a Service basics

Disaster Recovery as a Service is one go-to solution that revolutionizes DR planning. Implementing DRaaS could be an efficient process, easily accessible to non-DR experts. Learn about monitoring, testing, executing failovers and failbacks to ensure a "healthy" DR environment.

  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now