Results 1 to 5 of 5

Thread: Open DataReader associated with this Command in a Try/Catch code

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Aug 2012
    Posts
    17

    Open DataReader associated with this Command in a Try/Catch code

    In my programming, I've had this error come up a lot recently and its stopping me from testing my code properly. It has to do with a Try/Catch piece of code I think.

    The code is as follows:

    Code:
     Private Sub Main_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
            Try
                'TODO: This line of code loads data into the 'LinkedContacttbls.Contact' table. You can move, or remove it, as needed.
                Me.ContactTableAdapter.Fill(Me.LinkedContacttbls.Contact)
            Catch ex As Exception
                MsgBox(ex.Message)
    
            End Try
    
        End Sub
    
        Private Sub btnsave_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnsave.Click
            Me.Validate() 'Validate entry
            Me.ContactBindingSource.EndEdit() 'End the edit to the dataset
            Try
                Me.TableAdapterManager.UpdateAll(Me.LinkedContacttbls) 'update the entrys in the DB
                MsgBox("Records Saved", vbOKOnly + vbExclamation)
    
            Catch ex As Exception
                MsgBox(ex.Message)
            End Try
    
        End Sub
    
    Private Sub FirstNameTextBox_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles FirstNameTextBox.TextChanged
            Try
                Me.ContactTableAdapter.Search(Me.LinkedContacttbls.Contact, FirstNameTextBox.Text)
                LBSearch.Update()
            Catch op As System.InvalidOperationException
                System.Windows.Forms.MessageBox.Show(op.Message)
            End Try
    
    
        End Sub
    The error appears when I have the bottom function included in the code.

    I've search the internet and forums for an answer but they relate to specified DataReaders, however I dont think I have anything specified in my code as that.

    Any help would be appreciated! and if not if someone could point me in the right direction!

    Thank you

  2. #2
    Smooth Moperator techgnome's Avatar
    Join Date
    May 2002
    Posts
    34,531

    Re: Open DataReader associated with this Command in a Try/Catch code

    What error? And what's this got to do with a DataReader? I don't see a datareader anywhere in that code.

    -tg
    * I don't respond to private (PM) requests for help. It's not conducive to the general learning of others.*
    * I also don't respond to friend requests. Save a few bits and don't bother. I'll just end up rejecting anyways.*
    * How to get EFFECTIVE help: The Hitchhiker's Guide to Getting Help at VBF - Removing eels from your hovercraft *
    * How to Use Parameters * Create Disconnected ADO Recordset Clones * Set your VB6 ActiveX Compatibility * Get rid of those pesky VB Line Numbers * I swear I saved my data, where'd it run off to??? *

  3. #3

    Thread Starter
    Junior Member
    Join Date
    Aug 2012
    Posts
    17

    Re: Open DataReader associated with this Command in a Try/Catch code

    Sorry just realised I hadn't posted the error message above.

    Name:  error.jpg
Views: 298
Size:  16.9 KB

    This error, when I run the code in my first post.

  4. #4
    PowerPoster dunfiddlin's Avatar
    Join Date
    Jun 2012
    Posts
    8,245

    Re: Open DataReader associated with this Command in a Try/Catch code

    Well first off I don't think you really want to use the TextChanged event. You realise that it fires every time a single character is added or deleted from the textbox?

    Me.ContactTableAdapter.Search(Me.LinkedContacttbls.Contact, FirstNameTextBox.Text) - search isn't a native member of Adapter, how are you getting this past IDE?

    What is LBSearch? A databound ListBox? If so what's its binding?

  5. #5

    Thread Starter
    Junior Member
    Join Date
    Aug 2012
    Posts
    17

    Re: Open DataReader associated with this Command in a Try/Catch code

    IDE? I used that line of code from when you create a new ContactTableAdapter query

    LBSearch is a databound listbox and its bound to
    Datasource = ContactBindingSource
    DisplayMember = FirstName
    Value Member = Nothing
    Selected Value = ContactBindingSource - ContactID

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width