Search code examples
vb.netnullpointerexceptionfilloledbdataadapter

.NET OleDbDataAdapter .Fill throws ullPointerException


In my app, I use OleDbDataAdapter's & access data thru it to datasets. The code is :

        Dim id As Integer
    Try
        typeSql = "SELECT DOCHDR.dochdr_lDocId, TXNTYP.txntyp_cDocTypCat FROM TXNTYP INNER JOIN DOCHDR ON TXNTYP.txntyp_sDocTyp = DOCHDR.dochdr_sDocType WHERE ((DOCHDR.dochdr_lDocId)=395920);"
        typeAdap = New OleDb.OleDbDataAdapter(typeSql, connStr)
        typeDs = New DataSet()
        type_adap.Fill(type_ds) ' THROWS ERROR

    Catch ex As Exception
        Console.WriteLine("ERROR : " + ex.Message + " INNER " + ex.InnerException.ToString())
        Console.WriteLine("STACK = " + ex.StackTrace())
        Me.Close()
    End Try

I use other OleDbAdapter before this and other after this, but its this adap only that's throwing exception. Other all adaps/ds r filled the same way as above using different variables fo all.

MEssage : Object reference not set to an instance of an object.

If I execute the query in DB, it shows 1 row

I can't makeout what is wrong here. Can anyone point out where am I going wrong ??


Solution

  •     Dim id As Integer
    Try
        typeSql = "SELECT DOCHDR.dochdr_lDocId, TXNTYP.txntyp_cDocTypCat FROM TXNTYP INNER JOIN DOCHDR ON TXNTYP.txntyp_sDocTyp = DOCHDR.dochdr_sDocType WHERE ((DOCHDR.dochdr_lDocId)=395920);"
        typeAdap = New OleDb.OleDbDataAdapter(typeSql, connStr)
        typeDs = New DataSet()
        typeAdap.Fill(typeDs) ' THROWS ERROR
    
    Catch ex As Exception
        Console.WriteLine("ERROR : " + ex.Message + " INNER " + ex.InnerException.ToString())
        Console.WriteLine("STACK = " + ex.StackTrace())
        Me.Close()
    End Try