-
Aug 31st, 2012, 08:27 AM
#1
Thread Starter
Junior Member
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
-
Aug 31st, 2012, 08:44 AM
#2
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
-
Aug 31st, 2012, 08:49 AM
#3
Thread Starter
Junior Member
Re: Open DataReader associated with this Command in a Try/Catch code
Sorry just realised I hadn't posted the error message above.
This error, when I run the code in my first post.
-
Aug 31st, 2012, 08:55 AM
#4
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?
-
Aug 31st, 2012, 09:05 AM
#5
Thread Starter
Junior Member
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|