Results 1 to 4 of 4

Thread: VB 6 to VB 2019 execption

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Mar 2001
    Location
    Calgary
    Posts
    250

    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
    mannyso

  2. #2
    PowerPoster PlausiblyDamp's Avatar
    Join Date
    Dec 2016
    Location
    Pontypool, Wales
    Posts
    2,458

    Re: VB 6 to VB 2019 execption

    Quote Originally Posted by Manny Somarriba View Post
    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?

  3. #3
    Frenzied Member
    Join Date
    Feb 2003
    Posts
    1,807

    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.

  4. #4
    Super Moderator Shaggy Hiker's Avatar
    Join Date
    Aug 2002
    Location
    Idaho
    Posts
    38,989

    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
  •  



Click Here to Expand Forum to Full Width