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. Visual Basic
  4. Please help with Error in VB.Net Code :-(

Please help with Error in VB.Net Code :-(

Scheduled Pinned Locked Moved Visual Basic
helpcsharpsecurityannouncement
3 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.
  • S Offline
    S Offline
    Support123
    wrote on last edited by
    #1

    Hi all, I am using the following code: Dim connectionString As String = "Initial Catalog=DATABASEName;Data Source=INSTANCENameIthink;Integrated Security=SSPI;" Dim cn As SqlConnection = New SqlConnection(connectionString) Dim sqlCommand As SqlCommand = New SqlCommand("SELECT * FROM StagingEmployer ORDER BY StagingDate", cn) cn.Open() Dim TestRowset As SqlDataReader = sqlCommand.ExecuteReader() While TestRowset.Read() If (Convert.ToString(TestRowset(35)) = "U") Then Dim sqlCommand2 As SqlCommand = New SqlCommand("UPDATE stagingEmployerTest SET" _ + " [Employer_Number] = '" + Convert.ToString(TestRowset(0)) _ + "', [Name] = '" + Convert.ToString(TestRowset(1)) _ + "', [Trading_Name] = '" + Convert.ToString(TestRowset(2)) _ + "', [Business_Number] = '" + Convert.ToString(TestRowset(3)) _ + "', [Company_Number] = '" + Convert.ToString(TestRowset(4)) _ + "', [Tax_File_Number] = '" + Convert.ToString(TestRowset(5)) _ + "', [Street_Address_1] = '" + Convert.ToString(TestRowset(6)) _ + "', [Street_Address_2] = '" + Convert.ToString(TestRowset(7)) _ + "', [Street_Address_3] = '" + Convert.ToString(TestRowset(8)) _ + "', [Street_Suburb] = '" + Convert.ToString(TestRowset(9)) _ + "', [Street_State] = '" + Convert.ToString(TestRowset(10)) _ + "', [Street_Postcode] = '" + Convert.ToString(TestRowset(11)) _ + "', [Street_Country] = '" + Convert.ToString(TestRowset(12)) _ + "', [Postal_Address_1] = '" + Convert.ToString(TestRowset(13)) _ + "', [Postal_Address_2] = '" + Convert.ToString(TestRowset(14)) _ + "', [Postal_Address_3] = '" + Convert.ToString(TestRowset(15)) _ + "', [Postal_Suburb] = '" + Convert.ToString(TestRowset(16)) _ + "', [Postal_State] = '" + Convert.ToString(TestRowset(17)) _ + "', [Postal_Postcode] = '" + Convert.ToString(TestRowset(18)) _ + "', [Postal_Country] = '" + Convert.ToString(TestRowset(19)) _ + "', [Contact_Name] = '" + Convert.ToString(TestRowset(20)) _ + "', [Contact_Title] = '" + Convert.ToString(TestRowset(21)) _ + "', [Contact_Salutation] = '" + Convert.ToString(TestRowset(22)) _ + "', [Phone] = '" + Convert.ToString(TestRowset(23)) _ + "', [Fax] = '" + Convert.ToString(TestRowset(24)) _ + "', [Email] = '" + Convert.ToString(TestRowset(25)) _ + "', [Broker] = '" + Convert.ToString(TestRowset(26)) _ + "', [Underwriter] = '" + Convert.ToString(TestRowset(27)) _ + "', [Diplomatic_Indemnity] = '" + Convert.ToString(TestRowset(28)) _ + "', [Status] = '" + Convert.ToString(TestRowset(29)) _ + "', [Image] = '" + Convert.ToString(TestRowset(30)) _ +

    D 1 Reply Last reply
    0
    • S Support123

      Hi all, I am using the following code: Dim connectionString As String = "Initial Catalog=DATABASEName;Data Source=INSTANCENameIthink;Integrated Security=SSPI;" Dim cn As SqlConnection = New SqlConnection(connectionString) Dim sqlCommand As SqlCommand = New SqlCommand("SELECT * FROM StagingEmployer ORDER BY StagingDate", cn) cn.Open() Dim TestRowset As SqlDataReader = sqlCommand.ExecuteReader() While TestRowset.Read() If (Convert.ToString(TestRowset(35)) = "U") Then Dim sqlCommand2 As SqlCommand = New SqlCommand("UPDATE stagingEmployerTest SET" _ + " [Employer_Number] = '" + Convert.ToString(TestRowset(0)) _ + "', [Name] = '" + Convert.ToString(TestRowset(1)) _ + "', [Trading_Name] = '" + Convert.ToString(TestRowset(2)) _ + "', [Business_Number] = '" + Convert.ToString(TestRowset(3)) _ + "', [Company_Number] = '" + Convert.ToString(TestRowset(4)) _ + "', [Tax_File_Number] = '" + Convert.ToString(TestRowset(5)) _ + "', [Street_Address_1] = '" + Convert.ToString(TestRowset(6)) _ + "', [Street_Address_2] = '" + Convert.ToString(TestRowset(7)) _ + "', [Street_Address_3] = '" + Convert.ToString(TestRowset(8)) _ + "', [Street_Suburb] = '" + Convert.ToString(TestRowset(9)) _ + "', [Street_State] = '" + Convert.ToString(TestRowset(10)) _ + "', [Street_Postcode] = '" + Convert.ToString(TestRowset(11)) _ + "', [Street_Country] = '" + Convert.ToString(TestRowset(12)) _ + "', [Postal_Address_1] = '" + Convert.ToString(TestRowset(13)) _ + "', [Postal_Address_2] = '" + Convert.ToString(TestRowset(14)) _ + "', [Postal_Address_3] = '" + Convert.ToString(TestRowset(15)) _ + "', [Postal_Suburb] = '" + Convert.ToString(TestRowset(16)) _ + "', [Postal_State] = '" + Convert.ToString(TestRowset(17)) _ + "', [Postal_Postcode] = '" + Convert.ToString(TestRowset(18)) _ + "', [Postal_Country] = '" + Convert.ToString(TestRowset(19)) _ + "', [Contact_Name] = '" + Convert.ToString(TestRowset(20)) _ + "', [Contact_Title] = '" + Convert.ToString(TestRowset(21)) _ + "', [Contact_Salutation] = '" + Convert.ToString(TestRowset(22)) _ + "', [Phone] = '" + Convert.ToString(TestRowset(23)) _ + "', [Fax] = '" + Convert.ToString(TestRowset(24)) _ + "', [Email] = '" + Convert.ToString(TestRowset(25)) _ + "', [Broker] = '" + Convert.ToString(TestRowset(26)) _ + "', [Underwriter] = '" + Convert.ToString(TestRowset(27)) _ + "', [Diplomatic_Indemnity] = '" + Convert.ToString(TestRowset(28)) _ + "', [Status] = '" + Convert.ToString(TestRowset(29)) _ + "', [Image] = '" + Convert.ToString(TestRowset(30)) _ +

      D Offline
      D Offline
      Dave Kreskowiak
      wrote on last edited by
      #2

      The error is pretty self-explanitory. When you created your first SqlCommand object, you told it what the SQL statement was it was supposed to execute AND you told it which SqlConnection object to use. When you created your second SqlCommand object, you never told it which SqlConnection to use, which I believe you called cn.

      A guide to posting questions on CodeProject[^]
      Dave Kreskowiak Microsoft MVP Visual Developer - Visual Basic
           2006, 2007

      S 1 Reply Last reply
      0
      • D Dave Kreskowiak

        The error is pretty self-explanitory. When you created your first SqlCommand object, you told it what the SQL statement was it was supposed to execute AND you told it which SqlConnection object to use. When you created your second SqlCommand object, you never told it which SqlConnection to use, which I believe you called cn.

        A guide to posting questions on CodeProject[^]
        Dave Kreskowiak Microsoft MVP Visual Developer - Visual Basic
             2006, 2007

        S Offline
        S Offline
        Support123
        wrote on last edited by
        #3

        okay, thanks. :-)

        "Many of life's failures are people who did not realize how close they were to success when they gave up." Thomas A. Edison

        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