Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Visual Basic > VB 6 Visual Basic 6 > VB Databases Basics
|
VB Databases Basics Beginning-level VB coding questions specific to using VB with databases. Issues not specific to database use will be redirected to other forums.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the VB Databases Basics section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old June 19th, 2006, 05:12 PM
Registered User
 
Join Date: Jun 2006
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to Nosfe_X
Default Error: Object Reference not set to an instance.

Hi everybody

Follow the curse of my report aplication, i can join two datasets but vb .net send me a message error: "An unhandled exception of type "System.NullReferenceException" ocurred in RECON REPORT.exe. Aditional Information: Object reference not set an instance of an object".
I glad you help.

It is my code:

 xlsel = "Provider=Microsoft.Jet.OLEDB.4.0; Data Source=C:\Proyecto RECON Report\v0.1\RECON REPORT\recon_db.mdb"
        Try
            'Open connection
            bdconnection = New OleDbConnection(xlsel)
            bdconnection.Open()
        Catch ex As Exception
            MsgBox(" Error openning the connection :" & vbCrLf & ex.Message)
            Labled.Text = "Error"
            Exit Sub
        End Try

        ds2excel = New Data.DataSet
        xlsel = "Provider=Microsoft.Jet.OLEDB.4.0; Data Source=C:\Proyecto RECON Report\v0.1\RECON REPORT\recon_db.mdb"
        Try
            'Open connection
            bdconnection = New OleDbConnection(xlsel)
            bdconnection.Open()
        Catch ex As Exception
            MsgBox(" Error openning the connection :" & vbCrLf & ex.Message)
            Exit Sub
        End Try

        'master part_numbs
        xsqlmst = "SELECT masters.[Part Number] " & _
                  "FROM masters;"

        'ercw data
        'ercw Def_Shipments
        xsql = "SELECT ercw.PARTNUMBER, Count([ercw.OUTCOME_CODE]) AS Def_Shipments " & _
               "FROM ercw " & _
               "GROUP BY ercw.PARTNUMBER, ercw.OUTCOME_CODE " & _
               "HAVING (((ercw.OUTCOME_CODE)= 'IW'))" & _
               "ORDER BY ercw.PARTNUMBER, ercw.OUTCOME_CODE;"

        'ercw IW
        xsql2 = "SELECT ercw.PARTNUMBER, Count([ercw.OUTCOME_CODE]) AS MECH " & _
                "FROM ercw " & _
                "GROUP BY ercw.PARTNUMBER, ercw.OUTCOME_CODE " & _
                "HAVING (((ercw.OUTCOME_CODE)='IW' Or (ercw.OUTCOME_CODE)='IW_SGT'))" & _
                "ORDER BY ercw.PARTNUMBER, ercw.OUTCOME_CODE;"

  bdmstadapter = New OleDbDataAdapter(xsqlmst, bdconnection)
        bdadapter = New OleDbDataAdapter(xsql, bdconnection)

 Try
            bdmstadapter.Fill(dsmasters)
            bdmstadapter.Dispose()

            bdadapter.Fill(dsDefShip)
            bdadapter.Dispose()

            bdconnection.Close()

        Catch ex As Exception
            MessageBox.Show("Error charging the dataset: " & vbCrLf & ex.Message)
        End Try

        'Fill the dataset

        Dim ds2row As DataRow
        ds2excel.Tables.Add("RECON_REPORT")
        ds2excel.Tables("RECON_REPORT").Columns.Add("PARTN UMBER")
        ds2excel.Tables("RECON_REPORT").Columns.Add("DEF_S HIPMENTS")

 For Counter = 0 To ds2excel.Tables("RECON_REPORT").Rows.Count
            ds2row = ds2excel.Tables("RECON_REPORT").NewRow()
'here marks my error
ds2row.Item("PARTNUMBER") = dsmasters.Tables("MASTERS").Rows(Counter).Item(0). ToString()
ds2excel.Tables("RECON_REPORT").Rows.Add(ds2row)
        Next Counter

 
Old June 20th, 2006, 01:00 PM
Friend of Wrox
 
Join Date: Nov 2004
Posts: 1,621
Thanks: 1
Thanked 3 Times in 3 Posts
Default

2 things.

#1, you have in at least 2 places
Code:
                "HAVING (((ercw.OUTCOME_CODE)='IW' Or (ercw.OUTCOME_CODE)='IW_SGT'))" & _
                "ORDER BY ercw.PARTNUMBER, ercw.OUTCOME_CODE;"
                In this SQL, all those parens are doing nothing for you, and the excess of characters hides that there ought to be a space at the end of the 1st line, but it is absent. Plus, since your SQL has only one table as a source, you need not fully qualify field names. So:
Code:
                "HAVING OUTCOME_CODE = 'IW' Or OUTCOME_CODE = 'IW_SGT' " & _
Code:
                "ORDER BY PARTNUMBER, OUTCOME_CODE;"
                Not a big change, but every little thing helps, if only a little.

#2, I suspect that in
Code:
ds2row.Item("PARTNUMBER") = dsmasters.Tables("MASTERS").Rows(Counter).Item(0).ToString()
the table ("MASTERS") didn't get filled with anything. One point at which that situation could be being created is at
Code:
bdmstadapter = New OleDbDataAdapter(xsqlmst, bdconnection)
At that point, if xsqlmst doesn't point to any records, you will get no data (obviously).

So I would put in a temporary test for whether the dataset has any records just immediately prior to where you are getting the error.
 
Old June 23rd, 2006, 04:10 PM
Registered User
 
Join Date: Jun 2006
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to Nosfe_X
Default

Thanks, I found the problem with this, i glad your help :D






Similar Threads
Thread Thread Starter Forum Replies Last Post
Error - Object reference not set to an instance ? venkikrao VB.NET 2 July 5th, 2007 01:00 AM
Object reference not set to an instance of an obje hertendreef ASP.NET 2.0 Basics 3 July 1st, 2007 02:16 PM
Object reference not set to an instance of an obj. Dwizz VB.NET 2002/2003 Basics 8 June 1st, 2005 08:28 AM
Object Reference is Not Set to an Instance of an O blackinwhite General .NET 4 February 1st, 2005 05:42 AM
Object reference not set to an instance... steelman BOOK: ASP.NET Website Programming Problem-Design-Solution 6 May 7th, 2004 02:03 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.