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
CODE PROJECT For Those Who Code
  • Home
  • Articles
  • FAQ
Community
  1. Home
  2. General Programming
  3. Visual Basic
  4. how to reload dataReader?

how to reload dataReader?

Scheduled Pinned Locked Moved Visual Basic
businesshelptutorialquestion
7 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.
  • L Offline
    L Offline
    Lisana
    wrote on last edited by
    #1

    I have problem to reload DataReader in my app. Here is my code: Private Function ContactView() Dim DA As New OleDbDataAdapter Dim DR As OleDbDataReader objConn.Open() DA.SelectCommand = New OleDbCommand DA.SelectCommand.Connection = objConn DA.SelectCommand.CommandType = CommandType.Text DA.SelectCommand.CommandText = _ "SELECT primary_contact, entity_id, ISNULL(first_name, '') + ' ' + ISNULL(last_name, '') AS Name, ISNULL(company, '') " & _ "AS Company, ISNULL(business_phone, '') AS phone, ISNULL(home_phone, '') AS homePhone, ISNULL(pager, '') AS Pager, " & _ "ISNULL(mobile_phone, '') AS mobilePhone, ISNULL(business_fax, '') AS fax, ISNULL(email, '') AS email " & _ "FROM Contacts WHERE (status = 1) AND client_entity_id = " & client_entityID & " ORDER BY last_name, first_name" DR = DA.SelectCommand.ExecuteReader Dim y = 72 Dim primaryContact As Boolean Dim entity As Int32 Dim fullName, phone, fax, homePhone, cellPhone, email, company, pager As String Do While DR.Read() primaryContact = DR.GetBoolean(0) entity = DR.GetInt32(1) fullName = DR.GetString(2) company = DR.GetString(3) phone = DR.GetString(4) homePhone = DR.GetString(5) pager = DR.GetString(6) cellPhone = DR.GetString(7) fax = DR.GetString(8) email = DR.GetString(9) 'create a checked button If primaryContact = True Then Dim aImageButton As New Button With aImageButton Dim imagePath As String = Path.Combine(Application.StartupPath, "checkbox_checked.gif") .Image = Image.FromFile(imagePath) .Name = entity .Text = "" .ImageAlign = ContentAlignment.MiddleCenter .FlatStyle = FlatStyle.Flat .Location = New Point(10, y) .Width = 20 .Height = 20 End With ' Attach the Click Event handler AddHandler aImageButton.Click, AddressOf ImageButtonClickHandler ' Finally, add the control to the Form tpgContact.Controls.Add(aImag

    D 1 Reply Last reply
    0
    • L Lisana

      I have problem to reload DataReader in my app. Here is my code: Private Function ContactView() Dim DA As New OleDbDataAdapter Dim DR As OleDbDataReader objConn.Open() DA.SelectCommand = New OleDbCommand DA.SelectCommand.Connection = objConn DA.SelectCommand.CommandType = CommandType.Text DA.SelectCommand.CommandText = _ "SELECT primary_contact, entity_id, ISNULL(first_name, '') + ' ' + ISNULL(last_name, '') AS Name, ISNULL(company, '') " & _ "AS Company, ISNULL(business_phone, '') AS phone, ISNULL(home_phone, '') AS homePhone, ISNULL(pager, '') AS Pager, " & _ "ISNULL(mobile_phone, '') AS mobilePhone, ISNULL(business_fax, '') AS fax, ISNULL(email, '') AS email " & _ "FROM Contacts WHERE (status = 1) AND client_entity_id = " & client_entityID & " ORDER BY last_name, first_name" DR = DA.SelectCommand.ExecuteReader Dim y = 72 Dim primaryContact As Boolean Dim entity As Int32 Dim fullName, phone, fax, homePhone, cellPhone, email, company, pager As String Do While DR.Read() primaryContact = DR.GetBoolean(0) entity = DR.GetInt32(1) fullName = DR.GetString(2) company = DR.GetString(3) phone = DR.GetString(4) homePhone = DR.GetString(5) pager = DR.GetString(6) cellPhone = DR.GetString(7) fax = DR.GetString(8) email = DR.GetString(9) 'create a checked button If primaryContact = True Then Dim aImageButton As New Button With aImageButton Dim imagePath As String = Path.Combine(Application.StartupPath, "checkbox_checked.gif") .Image = Image.FromFile(imagePath) .Name = entity .Text = "" .ImageAlign = ContentAlignment.MiddleCenter .FlatStyle = FlatStyle.Flat .Location = New Point(10, y) .Width = 20 .Height = 20 End With ' Attach the Click Event handler AddHandler aImageButton.Click, AddressOf ImageButtonClickHandler ' Finally, add the control to the Form tpgContact.Controls.Add(aImag

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

      The DataReader object returns table rows in a "forward-only" manner. Meaning you can't rewind it and re-read the row that it just returned. The only way to get it to go backwards is to destroy the current DataReader object and create a new one, which will start returning rows from the beginning of the table again. RageInTheMachine9532 "...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome

      L 1 Reply Last reply
      0
      • D Dave Kreskowiak

        The DataReader object returns table rows in a "forward-only" manner. Meaning you can't rewind it and re-read the row that it just returned. The only way to get it to go backwards is to destroy the current DataReader object and create a new one, which will start returning rows from the beginning of the table again. RageInTheMachine9532 "...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome

        L Offline
        L Offline
        Lisana
        wrote on last edited by
        #3

        where and how to destroy the current dataReader in my app? Lisa

        D 1 Reply Last reply
        0
        • L Lisana

          where and how to destroy the current dataReader in my app? Lisa

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

          In your code, the DataReader that you create in the ContactView function is destroyed when execution reaches the end of the function. A new one is created and destroyed every time you execute ContactView. In your code, though, you have no way of destroying all the controls you made so you can create new ones with the updated data. I get the feeling that your code IS getting the updated values from the database, but since you never destroyed the controls with the old data, the new controls your creating are being created BEHIND the controls you already have, and are therefore not visible. IMHO, you've really got to use a DataGrid for this. You'll end up getting the functionality you want with about half the lines code that you've already written, and have yet to write more to get it to really work. RageInTheMachine9532 "...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome

          L 1 Reply Last reply
          0
          • D Dave Kreskowiak

            In your code, the DataReader that you create in the ContactView function is destroyed when execution reaches the end of the function. A new one is created and destroyed every time you execute ContactView. In your code, though, you have no way of destroying all the controls you made so you can create new ones with the updated data. I get the feeling that your code IS getting the updated values from the database, but since you never destroyed the controls with the old data, the new controls your creating are being created BEHIND the controls you already have, and are therefore not visible. IMHO, you've really got to use a DataGrid for this. You'll end up getting the functionality you want with about half the lines code that you've already written, and have yet to write more to get it to really work. RageInTheMachine9532 "...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome

            L Offline
            L Offline
            Lisana
            wrote on last edited by
            #5

            I want to user DataGrid, but how can I have buttons and combobox inside the datagrid? Lisa

            D 1 Reply Last reply
            0
            • L Lisana

              I want to user DataGrid, but how can I have buttons and combobox inside the datagrid? Lisa

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

              I'm trying to find a good tutorial on the custom DataGrid's for Windows Forms, but have so far come up emtpy. I keep finding everything under the sun for the ASP.NET DataGrid, though. How sad is that?! RageInTheMachine9532 "...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome

              L 1 Reply Last reply
              0
              • D Dave Kreskowiak

                I'm trying to find a good tutorial on the custom DataGrid's for Windows Forms, but have so far come up emtpy. I keep finding everything under the sun for the ASP.NET DataGrid, though. How sad is that?! RageInTheMachine9532 "...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome

                L Offline
                L Offline
                Lisana
                wrote on last edited by
                #7

                thanks for your trying.. Lisa

                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