We help IT Professionals succeed at work.

Object Reference not set Error

Declan Basile
on
61 Views
Last Modified: 2019-03-21
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?
Comment
Watch Question

CERTIFIED EXPERT

Commented:
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

This one is on us!
(Get your first solution completely free - no credit card required)
UNLOCK SOLUTION
Unlock the solution to this question.
Join our community and discover your potential

Experts Exchange is the only place where you can interact directly with leading experts in the technology field. Become a member today and access the collective knowledge of thousands of technology experts.

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.