Avatar of Declan Basile
Declan BasileFlag for United States of America asked on

Object Reference not set Error

In vb.net, I have a procedure declaration ...

        Private Sub SetSqlDataAdapter(ByRef da As SqlDataAdapter, strTableName As String)

And a call to it ...

        dap1 = New SqlDataAdapter(cmd1)
        Call SetSqlDataAdapter(dap1, "Returns")

dap1 is declared globally in the Form Class  ...

        Dim dap1 As New SqlDataAdapter

Why am I getting the exception "Object reference not set to an instance of an object" on the line that calls the procedure?
Visual Basic.NET

Avatar of undefined
Last Comment
Declan Basile

8/22/2022 - Mon
Ryan Chong

Why am I getting the exception "Object reference not set to an instance of an object" on the line that calls the procedure?

have you successfully built/ rebuilt your project?

this worked for me:

Imports System.Data.SqlClient

Public Class Form1
    Dim dap1 As New SqlDataAdapter
    Dim cmd1 As New SqlCommand

    Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load

        dap1 = New SqlDataAdapter(cmd1)
        Call SetSqlDataAdapter(dap1, "Returns")

        MsgBox("Done")
    End Sub

    Private Sub SetSqlDataAdapter(ByRef da As SqlDataAdapter, strTableName As String)
        'do your stuffs here
    End Sub
End Class

Open in new window

ASKER CERTIFIED SOLUTION
Declan Basile

Log in or sign up to see answer
Become an EE member today7-DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform
Sign up - Free for 7 days
or
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.
See how we're fighting big data
Not exactly the question you had in mind?
Sign up for an EE membership and get your own personalized solution. With an EE membership, you can ask unlimited troubleshooting, research, or opinion questions.
ask a question
Your help has saved me hundreds of hours of internet surfing.
fblack61