Why am I getting this error during design time?

Error Number 5: Key cannot be null

If Me.Visible = True Then
            If RetrieveSubjectsAndSection(Username, Subject) = True Then
                InsertSubjectsAndSection(Username,Subject)
            End If
        End If

RetrieveSubjectsAndSection function checks if record exist. The code is written inside a Usercontrol. Also I have not ran the program yet.


Everytime I move the Usercontrol on the form, the error pops up. As if it is trying to connect.

The Visual Studio IDE uses reflection to render user controls so it is compiling and loading the control which runs the code in the constructur and user control's load event.

Take a look at this article on detecting if the code is being run from a designer:
http://vidmar.net/weblog/archive/2005/04/11/1246.aspx

I found the solution, thanks snake.

If Me.DesignMode = False then
'control/form is in Runtime
end if
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.