473,404 Members | 2,213 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,404 software developers and data experts.

Invalid Operation Exception was unhandled

lotus18
866 512MB
WaAh!

My form was working fine earlier but later it displays Invalid Operation Exception was unhandled. I don't know what's wrong with my form every time I load it.I checked its codes but I find what's wrong with it.

If I'm going to remove Transaction.Courses.Show(False, txtSearch.Text) at line #2 of frmCourses it works fine. Of course I cannot filter the records : (

This is my sample codes

clsCourses
Expand|Select|Wrap|Line Numbers
  1. #Region " Variable Declarations..."
  2.     Private ModColor As Boolean
  3.     Private SQLString As String
  4.     Private i As Integer
  5.     Private adItem As ListViewItem
  6.     Private rsCourses As OleDbDataReader
  7.     Private cmdCourses As New OleDbCommand
  8. #End Region
  9.  
  10. Public Sub Show(ByVal ShowAllList As Boolean, Optional ByVal Search As String = vbNullString)
  11.         Windows.Forms.Cursor.Current = Cursors.WaitCursor
  12.         If ShowAllList Then
  13.             SQLString = "Select * From Courses Order By Title ASC"
  14.         Else
  15.             SQLString = "Select * From Courses Where CourseID Like '%" & Search & _
  16.             "%' Or Title Like '%" & Search & "%' Or Description Like '%" & _
  17.             Search & "%' Order By Title ASC"
  18.         End If
  19.  
  20.         Call SetConnection()
  21.         cmdCourses = New OleDbCommand(SQLString, dbConnection)
  22.         cmdCourses.CommandType = CommandType.Text
  23.         rsCourses = cmdCourses.ExecuteReader
  24.  
  25.         frmCourses.lvwCourses.Items.Clear()
  26.         While rsCourses.Read
  27.             adItem = frmCourses.lvwCourses.Items.Add(rsCourses(0), 0)   'Course ID
  28.             adItem.SubItems.Add(rsCourses(1))                           'Title
  29.             adItem.SubItems.Add(rsCourses(2))                           'Description
  30.         End While
  31.  
  32.         frmCourses.lblTotalRecords.Text = "Total Records: " & frmCourses.lvwCourses.Items.Count
  33.  
  34.         If frmCourses.lvwCourses.Items.Count > 0 Then
  35.             frmCourses.lblShowStatus.Visible = False
  36.         Else
  37.             frmCourses.lblShowStatus.Visible = True
  38.         End If
  39.  
  40.         For i = 0 To frmCourses.lvwCourses.Items.Count - 1
  41.             If ModColor = True Then
  42.                 frmCourses.lvwCourses.Items(i).BackColor = Color.AliceBlue
  43.                 ModColor = False
  44.             Else
  45.                 frmCourses.lvwCourses.Items(i).BackColor = Color.White
  46.                 ModColor = True
  47.             End If
  48.         Next
  49.  
  50.         rsCourses.Close()
  51.         Call CloseConnection()
  52.         Windows.Forms.Cursor.Current = Cursors.Default
  53.     End Sub
frmCourses
Expand|Select|Wrap|Line Numbers
  1. Private Sub txtSearch_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles txtSearch.TextChanged
  2.         Transaction.Courses.Show(False, txtSearch.Text)
  3.     End Sub
  4.  
  5. Private Sub frmCourses_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
  6.         Main.SetChildForm(frmMain, Me)
  7.         Transaction.Courses.Show(True)
  8.     End Sub
  9.  
Rey Sean
May 5 '08 #1
5 3178
kenobewan
4,871 Expert 4TB
An integer, eg an id, can't be like another incl in an sql statement. Suggest using try catch blocks and/ or other error handling. HTH.
May 5 '08 #2
lotus18
866 512MB
An integer, eg an id, can't be like another incl in an sql statement. Suggest using try catch blocks and/ or other error handling. HTH.
Hi

Thanks for your reply : )

I've used try and catch blocks as what you've said but still it gives me an error result, An error occurred creating the form. See Exception.InnerException for details. The error is: The form referred to itself during construction from a default instance, which led to infinite recursion. Within the Form's constructor refer to the form using 'Me.'

BTW, what do you mean by incl?

Rey Sean
May 7 '08 #3
Plater
7,872 Expert 4TB
Well what I saw turned out to be exactly what the error was giving you. So I think I am right on this.

In your form_load function (which gets called everytime it's shown) you are trying to SHOW it again. Which would lead to infinite recurrsion.
Remove the unneeded .Show() call like you said to make it work.
It shouldn't be there anyway.
May 7 '08 #4
lotus18
866 512MB
Well what I saw turned out to be exactly what the error was giving you. So I think I am right on this.

In your form_load function (which gets called everytime it's shown) you are trying to SHOW it again. Which would lead to infinite recurrsion.
Remove the unneeded .Show() call like you said to make it work.
It shouldn't be there anyway.
If that is the reason I think I should create another method for clsCourses for filtering the records. But I don't think that is the best idea because I am going to create another method again with almost the same as with the showing of records the only difference between them is their sql statement. Can you give me another idea how to handle this?

Rey Sean
May 8 '08 #5
Plater
7,872 Expert 4TB
Well lets start off with why are you continuing to make another instance of your class? (Or at least calling Show many times)
If you want to hide the form and then unhide it, use the Visible property?
May 8 '08 #6

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: Ron | last post by:
I am trying to run asp.net pages. The server is accessed via http://sitename/username I have verified it is using port 80 and aspx extensions are configured. But when I run and asp.net page I...
8
by: Glenn A. Harlan | last post by:
Why am I receiving the below error when calling - Path.GetTempFileName() The directory name is invalid. Description: An unhandled exception occurred during the execution of the current web...
0
by: simpsoro | last post by:
I am trying to run asp.net pages. The server is accessed by students via http://sitename/username I have verified it is using port 80 and aspx extensions are configured. But when I run and...
1
by: King Kong | last post by:
we are facing this kind of error when we double click the infragistic web grid please help me on this Regards Moid Iqbal Server Error in '/NetworkAccess' Application....
0
by: Ron Simpson | last post by:
I am trying to run asp.net pages. The server is accessed via http://sitename/username I have verified it is using port 80 and aspx extensions are configured. But when I run and asp.net page I...
5
by: lds | last post by:
I am getting the following error: The "SendUsing" configuration value is invalid. Description: An unhandled exception occurred during the execution of the current web request. Please review the...
4
by: VB Programmer | last post by:
When I run my ASP.NET 2.0 web app on my dev machine it works perfect. When I precomile it to my web deployment project and then copy the debug files to my web server I get this problem when trying...
1
by: Ron | last post by:
Hi, I had a stored procedure on SQL 2000 server to run calculation with large amount of data. When I called this stored procedure via System.Data.SqlClient.SqlCommand on production, i got error...
10
by: Jim Underwood | last post by:
I am having a problem with my web page timng out while retrieving a long runnign report (90-120 seconds. I have tried modifying several settings in various places and cannot get it to run for more...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.