473,588 Members | 2,460 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Invalid Operation Exception was unhandled

lotus18
866 Contributor
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.Cou rses.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 3192
kenobewan
4,871 Recognized Expert Specialist
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 Contributor
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.Inner Exception 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 Recognized Expert Expert
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 Contributor
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 Recognized Expert Expert
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
3867
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 get the following error: Invalid file name for monitoring: 'E:\'. File names for monitoring must have absolute paths, and no wildcards. Description: An unhandled exception occurred during the
8
17463
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 request. Please review the stack trace for more information about the error and where it originated in the code. Exception Details: System.IO.IOException: The directory name is invalid.
0
1473
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 asp.net page I get the following error: Invalid file name for monitoring: 'E:\'. File names for monitoring must have absolute paths, and no wildcards. Description: An unhandled exception occurred during the
1
10149
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
1613
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 get the following error: Invalid file name for monitoring: 'E:\'. File names for monitoring must have absolute paths, and no wildcards. Description: An unhandled exception occurred during the
5
15115
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 stack trace for more information about the error and where it originated in the code. Exception Details: System.Runtime.InteropServices.COMException: The "SendUsing" configuration value is invalid.
4
13170
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 to login (obviously it's using ASPNETDB.mdf). Any ideas? Server Error in '/' Application. --------------------------------------------------------------------------------
1
45155
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 as: (i tried to run the stored procedure on query analyzer, and it works well) Timeout expired. The timeout period elapsed prior to completion of the operation or the server is not responding. Description: An unhandled exception occurred...
10
19137
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 than 90 seconds. I am running VS.Net and the app is ASP.Net, written using VB.Net. The app calls an asp.Net web service to retrieve the report. Both the web site and the web service are running locally on my PC. I have tried modifying the...
0
7929
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8222
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
7984
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
6634
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5398
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
3847
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
3883
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
1458
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
1195
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.