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. sqldatareader and inner join problem, not getting all records, PLEASE HELP

sqldatareader and inner join problem, not getting all records, PLEASE HELP

Scheduled Pinned Locked Moved ASP.NET
databasehelpquestion
6 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.
  • O Offline
    O Offline
    orsini
    wrote on last edited by
    #1

    i have this code, when i run this page, this reader dont bring the first record. i ran this sql(SELECT) on the sql database and runs fine, and if i put the seme SELECT in a Sqldatasource and bind the griview, it works fine too. what is wrong with this reader? ****************** any idea. THIS WORKS

    SqlDataSource1.SelectCommand = "SELECT products.pid, products.pname, flavors.fl_name, product_flavors.flavor_icon FROM product_flavors LEFT JOIN flavors ON product_flavors.flavorsid = flavors.flavorsid LEFT JOIN products ON product_flavors.pid=products.pid WHERE products.pid = 84"
    ProductListView.DataSource = SqlDataSource1
    ProductListView.DataBind()

    ********************** THIS NOT BRING ALL THE RECORDS. ALWAYS LEAVE ONE OUT.I THINK THE FIRST ONE.

    Dim conn As SqlConnection
    Dim cmd As SqlCommand
    Dim cmdString As String = "SELECT products.pid, products.pname, flavors.fl_name, product_flavors.flavor_icon FROM product_flavors LEFT JOIN flavors ON product_flavors.flavorsid = flavors.flavorsid LEFT JOIN products ON product_flavors.pid=products.pid WHERE products.pid = 84"
    conn = New SqlConnection(ConfigurationManager.ConnectionStrings("eConnectionString").ToString)
    cmd = New SqlCommand(cmdString, conn)
    conn.Open()
    Dim myReader As SqlDataReader
    myReader = cmd.ExecuteReader()
    myReader.Read()
    GridView1.DataSource = myReader
    GridView1.DataBind()
    conn.Close()

    S N 2 Replies Last reply
    0
    • O orsini

      i have this code, when i run this page, this reader dont bring the first record. i ran this sql(SELECT) on the sql database and runs fine, and if i put the seme SELECT in a Sqldatasource and bind the griview, it works fine too. what is wrong with this reader? ****************** any idea. THIS WORKS

      SqlDataSource1.SelectCommand = "SELECT products.pid, products.pname, flavors.fl_name, product_flavors.flavor_icon FROM product_flavors LEFT JOIN flavors ON product_flavors.flavorsid = flavors.flavorsid LEFT JOIN products ON product_flavors.pid=products.pid WHERE products.pid = 84"
      ProductListView.DataSource = SqlDataSource1
      ProductListView.DataBind()

      ********************** THIS NOT BRING ALL THE RECORDS. ALWAYS LEAVE ONE OUT.I THINK THE FIRST ONE.

      Dim conn As SqlConnection
      Dim cmd As SqlCommand
      Dim cmdString As String = "SELECT products.pid, products.pname, flavors.fl_name, product_flavors.flavor_icon FROM product_flavors LEFT JOIN flavors ON product_flavors.flavorsid = flavors.flavorsid LEFT JOIN products ON product_flavors.pid=products.pid WHERE products.pid = 84"
      conn = New SqlConnection(ConfigurationManager.ConnectionStrings("eConnectionString").ToString)
      cmd = New SqlCommand(cmdString, conn)
      conn.Open()
      Dim myReader As SqlDataReader
      myReader = cmd.ExecuteReader()
      myReader.Read()
      GridView1.DataSource = myReader
      GridView1.DataBind()
      conn.Close()

      S Offline
      S Offline
      Sherin Iranimose
      wrote on last edited by
      #2

      orsini wrote:

      myReader.Read()

      I think the above line is the problem When you Use Read reader move to next record. Instead of binding the reader try to bind DataTable.

      orsini wrote:

      cmd = New SqlCommand(cmdString, conn) conn.Open() Dim myReader As SqlDataReader myReader = cmd.ExecuteReader() myReader.Read() GridView1.DataSource = myReader

      Dim adp as new SqlDataAdpter(cmdString,conn); Dim dt as new DataTable adp.Fill(dt); GridView1.DataSource = dt

      EVEN THE WORD IMPOSSIBLE SAYS I M POSSIBLE.

      N 1 Reply Last reply
      0
      • O orsini

        i have this code, when i run this page, this reader dont bring the first record. i ran this sql(SELECT) on the sql database and runs fine, and if i put the seme SELECT in a Sqldatasource and bind the griview, it works fine too. what is wrong with this reader? ****************** any idea. THIS WORKS

        SqlDataSource1.SelectCommand = "SELECT products.pid, products.pname, flavors.fl_name, product_flavors.flavor_icon FROM product_flavors LEFT JOIN flavors ON product_flavors.flavorsid = flavors.flavorsid LEFT JOIN products ON product_flavors.pid=products.pid WHERE products.pid = 84"
        ProductListView.DataSource = SqlDataSource1
        ProductListView.DataBind()

        ********************** THIS NOT BRING ALL THE RECORDS. ALWAYS LEAVE ONE OUT.I THINK THE FIRST ONE.

        Dim conn As SqlConnection
        Dim cmd As SqlCommand
        Dim cmdString As String = "SELECT products.pid, products.pname, flavors.fl_name, product_flavors.flavor_icon FROM product_flavors LEFT JOIN flavors ON product_flavors.flavorsid = flavors.flavorsid LEFT JOIN products ON product_flavors.pid=products.pid WHERE products.pid = 84"
        conn = New SqlConnection(ConfigurationManager.ConnectionStrings("eConnectionString").ToString)
        cmd = New SqlCommand(cmdString, conn)
        conn.Open()
        Dim myReader As SqlDataReader
        myReader = cmd.ExecuteReader()
        myReader.Read()
        GridView1.DataSource = myReader
        GridView1.DataBind()
        conn.Close()

        N Offline
        N Offline
        NeverHeardOfMe
        wrote on last edited by
        #3

        Try removing the line myReader.Read() before binding it to the GridView The DatReader is a forward-only cursor and you have moved it one record on by reading from it. You might want to check that ANY rows are returned first though - use If myReader.HasRows Then....

        O 1 Reply Last reply
        0
        • S Sherin Iranimose

          orsini wrote:

          myReader.Read()

          I think the above line is the problem When you Use Read reader move to next record. Instead of binding the reader try to bind DataTable.

          orsini wrote:

          cmd = New SqlCommand(cmdString, conn) conn.Open() Dim myReader As SqlDataReader myReader = cmd.ExecuteReader() myReader.Read() GridView1.DataSource = myReader

          Dim adp as new SqlDataAdpter(cmdString,conn); Dim dt as new DataTable adp.Fill(dt); GridView1.DataSource = dt

          EVEN THE WORD IMPOSSIBLE SAYS I M POSSIBLE.

          N Offline
          N Offline
          NeverHeardOfMe
          wrote on last edited by
          #4

          bah - your answer wasn't there when I started writing mine! :-)

          S 1 Reply Last reply
          0
          • N NeverHeardOfMe

            bah - your answer wasn't there when I started writing mine! :-)

            S Offline
            S Offline
            Sherin Iranimose
            wrote on last edited by
            #5

            :)

            EVEN THE WORD IMPOSSIBLE SAYS I M POSSIBLE.

            1 Reply Last reply
            0
            • N NeverHeardOfMe

              Try removing the line myReader.Read() before binding it to the GridView The DatReader is a forward-only cursor and you have moved it one record on by reading from it. You might want to check that ANY rows are returned first though - use If myReader.HasRows Then....

              O Offline
              O Offline
              orsini
              wrote on last edited by
              #6

              thank you so much, both answer are great, both worked fine, thanks again. I am trying to get away from those fance interface user and get more into the code behind. so, when I bind that productlistview. with the reader, i have a funcion that return the selected value.

              Public ReadOnly Property prodid() As String
              Get
              Return ProductListView.SelectedValue
              End Get
              End Property

              which i retrieve it in the next page. how can i tell the productlistview, that the datakeynames = myrreader("pid") from the code behind. thanks for your help.

              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