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. Web Development
  3. ASP.NET
  4. only first row from datareader gets affected

only first row from datareader gets affected

Scheduled Pinned Locked Moved ASP.NET
databasequestionannouncement
4 Posts 3 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
    svknair
    wrote on last edited by
    #1

    sqlstr = "select country , city FROM tbl_data WHERE RID in( " & ID & ") " dr = ''''''''''''''''''''exexuting the reader Ifdr.HasRows Then Whiledr.Read Dim datacountry =dr("country").ToString.Trim Dim datacity =dr("city").ToString.Trim MsgBox(datacountry & "===" & datacity) sqlstr = "SELECT user FROM tbl_info " _ & " WHERE country='" & drpcountry.SelectedItem.Text & "' AND city='" & drp city.SelectedItem.Text & "'" dr = ''''''''''''''''''''exexuting the reader Ifdr.HasRows Then Whiledr.Read sqlstr = "IF EXISTS (SELECT user, country, city FROM tbl_info " _ & " WHERE user='" &dr("user").ToString.Trim & "'" _ & " AND country='" & datacountry & "' AND city='" & datacity & "')" _ & " UPDATE tbl_info set user='" &dr("user").ToString.Trim & "' " _ & " WHERE user='" &dr("user").ToString.Trim & "' AND country='" & datacountry & "' AND city='" & datacity & "' " _ & " Else " _ & " INSERT INTO tbl_info(user,country, city) " _ & " VALUES ('" &dr("user").ToString.Trim & "','" & datacountry & "','" & datacity & "')" ''''''''''exexuting the query........ End While End If End While End If but in this only the first record from the country and city gets affected. all the records obtained in the reader shld get affected how do i rectify it

    C L 2 Replies Last reply
    0
    • S svknair

      sqlstr = "select country , city FROM tbl_data WHERE RID in( " & ID & ") " dr = ''''''''''''''''''''exexuting the reader Ifdr.HasRows Then Whiledr.Read Dim datacountry =dr("country").ToString.Trim Dim datacity =dr("city").ToString.Trim MsgBox(datacountry & "===" & datacity) sqlstr = "SELECT user FROM tbl_info " _ & " WHERE country='" & drpcountry.SelectedItem.Text & "' AND city='" & drp city.SelectedItem.Text & "'" dr = ''''''''''''''''''''exexuting the reader Ifdr.HasRows Then Whiledr.Read sqlstr = "IF EXISTS (SELECT user, country, city FROM tbl_info " _ & " WHERE user='" &dr("user").ToString.Trim & "'" _ & " AND country='" & datacountry & "' AND city='" & datacity & "')" _ & " UPDATE tbl_info set user='" &dr("user").ToString.Trim & "' " _ & " WHERE user='" &dr("user").ToString.Trim & "' AND country='" & datacountry & "' AND city='" & datacity & "' " _ & " Else " _ & " INSERT INTO tbl_info(user,country, city) " _ & " VALUES ('" &dr("user").ToString.Trim & "','" & datacountry & "','" & datacity & "')" ''''''''''exexuting the query........ End While End If End While End If but in this only the first record from the country and city gets affected. all the records obtained in the reader shld get affected how do i rectify it

      C Offline
      C Offline
      Christian Graus
      wrote on last edited by
      #2

      Have you ever used a debugger ?

      Christian Graus Driven to the arms of OSX by Vista. "I am new to programming world. I have been learning c# for about past four weeks. I am quite acquainted with the fundamentals of c#. Now I have to work on a project which converts given flat files to XML using the XML serialization method" - SK64 ( but the forums have stuff like this posted every day )

      1 Reply Last reply
      0
      • S svknair

        sqlstr = "select country , city FROM tbl_data WHERE RID in( " & ID & ") " dr = ''''''''''''''''''''exexuting the reader Ifdr.HasRows Then Whiledr.Read Dim datacountry =dr("country").ToString.Trim Dim datacity =dr("city").ToString.Trim MsgBox(datacountry & "===" & datacity) sqlstr = "SELECT user FROM tbl_info " _ & " WHERE country='" & drpcountry.SelectedItem.Text & "' AND city='" & drp city.SelectedItem.Text & "'" dr = ''''''''''''''''''''exexuting the reader Ifdr.HasRows Then Whiledr.Read sqlstr = "IF EXISTS (SELECT user, country, city FROM tbl_info " _ & " WHERE user='" &dr("user").ToString.Trim & "'" _ & " AND country='" & datacountry & "' AND city='" & datacity & "')" _ & " UPDATE tbl_info set user='" &dr("user").ToString.Trim & "' " _ & " WHERE user='" &dr("user").ToString.Trim & "' AND country='" & datacountry & "' AND city='" & datacity & "' " _ & " Else " _ & " INSERT INTO tbl_info(user,country, city) " _ & " VALUES ('" &dr("user").ToString.Trim & "','" & datacountry & "','" & datacity & "')" ''''''''''exexuting the query........ End While End If End While End If but in this only the first record from the country and city gets affected. all the records obtained in the reader shld get affected how do i rectify it

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

        From you code, it seems that the SqlDataReader variable 'dr' is re-builds again within the first while loop. Use another variable for inner data reader.

        C 1 Reply Last reply
        0
        • L Lost User

          From you code, it seems that the SqlDataReader variable 'dr' is re-builds again within the first while loop. Use another variable for inner data reader.

          C Offline
          C Offline
          Christian Graus
          wrote on last edited by
          #4

          I was hoping to instead teach him how to debug his own code, one run through in the debugger should have told him what was wrong.

          Christian Graus Driven to the arms of OSX by Vista. "I am new to programming world. I have been learning c# for about past four weeks. I am quite acquainted with the fundamentals of c#. Now I have to work on a project which converts given flat files to XML using the XML serialization method" - SK64 ( but the forums have stuff like this posted every day )

          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