-
Aug 23rd, 2020, 11:44 AM
#1
Thread Starter
Addicted Member
VB 6 to VB 2019 execption
I just starting to program in visual basic 2019 but, I program before in visual basic 6 I have this exception. VB 2019 does not recognice this codification how can I open this operation in VB 20019 somebody
know it please.
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
If cn.State = ConnectionState.Open Then cn.Close()
cn.ConnectionString = Ca.cnstring
cn.Open()
GetData("Select * from stockin")
_Clear()
End Sub
Message:
This exception was originally thrown at this call stack:
[External Code]
Stock_System.Form1.Form1_Load(Object, System.EventArgs) in Form1.vb
[External Code]
Thanks in advance
-
Aug 23rd, 2020, 11:51 AM
#2
Re: VB 6 to VB 2019 execption
Originally Posted by Manny Somarriba
I just starting to program in visual basic 2019 but, I program before in visual basic 6 I have this exception. VB 2019 does not recognice this codification how can I open this operation in VB 20019 somebody
know it please.
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
If cn.State = ConnectionState.Open Then cn.Close()
cn.ConnectionString = Ca.cnstring
cn.Open()
GetData("Select * from stockin")
_Clear()
End Sub
Message:
This exception was originally thrown at this call stack:
[External Code]
Stock_System.Form1.Form1_Load(Object, System.EventArgs) in Form1.vb
[External Code]
Thanks in advance
Which line gives the exception and what exception is it?
-
Aug 23rd, 2020, 12:24 PM
#3
Re: VB 6 to VB 2019 execption
Please use code tags to enclose your code. The "#" button above the message you're about to post. If you're importing the System namespace you can just write Object and EventArgs without System before them. Also I believe ByVal is unnecessary here.
-
Aug 23rd, 2020, 01:05 PM
#4
Re: VB 6 to VB 2019 execption
It isn't necessary, but at least some versions of VS will add it automatically if you leave it out, so that may not be something the OP did.
One thing about the code that may have nothing to do with the exception is that it is a very VB6 way of handling connections. In .NET, connection pooling works really well, so keeping a connection around, and open, is generally a pretty bad idea. Therefore, the way to do things is usually just to create the connection, open it, use it, dispose it. So, you might write:
Code:
Using cn As New Connection(yourConnectionStringHere)
cn.Open
'Do stuff here.
End Using
The End Using will properly clean up the connection, even if an exception is thrown while inside the using block. Thus, you don't need to deal with closing or disposing the connection. Instead, just use it and let the End Using take care of the clean up.
My usual boring signature: Nothing
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
|