Null Reference Exception

JesseH

Active member
Joined
Feb 9, 2006
Messages
42
Location
Sugar Land, TX
Programming Experience
10+
I am getting the error below on line "Dataset11.Clear()". I have no clue on how to fix it. Anybody kind enough to respond please remember that you are talking to a newbie.:eek:

Thanks in Advance.


"An unhandled exception of type 'System.NullReferenceException' occurred in EIMReconStart.exe
Additional information: Object reference not set to an instance of an object"
 
If that is the case then it is likely that Dataset11 hasn't been given a value or has been declared nothing before that line executes. Could you show the code you are using.
 
Code Used - Thanks for the help

VB.NET:
PublicClass APNotInGL
Inherits System.Windows.Forms.Form
#Region " Windows Form Designer generated code "
PublicSubNew()
MyBase.New()
'This call is required by the Windows Form Designer.
InitializeComponent()
'Add any initialization after the InitializeComponent() call
EndSub
'Form overrides dispose to clean up the component list.
ProtectedOverloadsOverridesSub Dispose(ByVal disposing AsBoolean)
If disposing Then
IfNot (components IsNothing) Then
components.Dispose()
EndIf
EndIf
MyBase.Dispose(disposing)
EndSub
'Required by the Windows Form Designer
Private components As System.ComponentModel.IContainer
'NOTE: The following procedure is required by the Windows Form Designer
'It can be modified using the Windows Form Designer. 
'Do not modify it using the code editor.
FriendWithEvents Label1 As System.Windows.Forms.Label
FriendWithEvents lblDate As System.Windows.Forms.Label
FriendWithEvents lblDateRange As System.Windows.Forms.Label
FriendWithEvents Label2 As System.Windows.Forms.Label
FriendWithEvents Label3 As System.Windows.Forms.Label
FriendWithEvents txtBegDt As _2gs_datetextbox.DateTextbox
FriendWithEvents txtEndDt As _2gs_datetextbox.DateTextbox
FriendWithEvents ErrorProvider1 As System.Windows.Forms.ErrorProvider
FriendWithEvents DataGrid1 As System.Windows.Forms.DataGrid
FriendWithEvents Label4 As System.Windows.Forms.Label
FriendWithEvents cmdDoSerach As System.Windows.Forms.Button
FriendWithEvents cmdReturn As System.Windows.Forms.Button
FriendWithEvents OdbcDataAdapter1 As System.Data.Odbc.OdbcDataAdapter
FriendWithEvents OdbcSelectCommand1 As System.Data.Odbc.OdbcCommand
FriendWithEvents OdbcInsertCommand1 As System.Data.Odbc.OdbcCommand
FriendWithEvents OdbcConnection1 As System.Data.Odbc.OdbcConnection
FriendWithEvents DataSet11 As EIMReconStart.DataSet1
FriendWithEvents DataSet12 As EIMReconStart.DataSet1
<System.Diagnostics.DebuggerStepThrough()> PrivateSub InitializeComponent()
Me.Label1 = New System.Windows.Forms.Label
Me.lblDate = New System.Windows.Forms.Label
Me.lblDateRange = New System.Windows.Forms.Label
Me.Label2 = New System.Windows.Forms.Label
Me.txtBegDt = New _2gs_datetextbox.DateTextbox
Me.Label3 = New System.Windows.Forms.Label
Me.txtEndDt = New _2gs_datetextbox.DateTextbox
Me.ErrorProvider1 = New System.Windows.Forms.ErrorProvider
Me.DataGrid1 = New System.Windows.Forms.DataGrid
Me.Label4 = New System.Windows.Forms.Label
Me.cmdDoSerach = New System.Windows.Forms.Button
Me.cmdReturn = New System.Windows.Forms.Button
Me.OdbcDataAdapter1 = New System.Data.Odbc.OdbcDataAdapter
Me.OdbcInsertCommand1 = New System.Data.Odbc.OdbcCommand
Me.OdbcConnection1 = New System.Data.Odbc.OdbcConnection
Me.OdbcSelectCommand1 = New System.Data.Odbc.OdbcCommand
Me.DataSet12 = New EIMReconStart.DataSet1
CType(Me.DataGrid1, System.ComponentModel.ISupportInitialize).BeginInit()
CType(Me.DataSet12, System.ComponentModel.ISupportInitialize).BeginInit()
Me.SuspendLayout()
'
'Label1
'
Me.Label1.Font = New System.Drawing.Font("Microsoft Sans Serif", 12.0!, 
System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
Me.Label1.Location = New System.Drawing.Point(248, 0)
Me.Label1.Name = "Label1"
Me.Label1.Size = New System.Drawing.Size(160, 23)
Me.Label1.TabIndex = 0
Me.Label1.Text = "AP Items Not In GL"
'
'lblDate
'
Me.lblDate.Location = New System.Drawing.Point(232, 24)
Me.lblDate.Name = "lblDate"
Me.lblDate.Size = New System.Drawing.Size(192, 24)
Me.lblDate.TabIndex = 2
Me.lblDate.TextAlign = System.Drawing.ContentAlignment.MiddleCenter
'
'lblDateRange
'
Me.lblDateRange.Location = New System.Drawing.Point(96, 80)
Me.lblDateRange.Name = "lblDateRange"
Me.lblDateRange.Size = New System.Drawing.Size(72, 23)
Me.lblDateRange.TabIndex = 3
Me.lblDateRange.Text = "Fron Date"
'
'Label2
'
Me.Label2.Location = New System.Drawing.Point(248, 48)
Me.Label2.Name = "Label2"
Me.Label2.Size = New System.Drawing.Size(136, 23)
Me.Label2.TabIndex = 4
Me.Label2.Text = "A/P Payables Date Range"
'
'txtBegDt
'
Me.txtBegDt.DateName = "BegDt"
Me.txtBegDt.Location = New System.Drawing.Point(200, 72)
Me.txtBegDt.Name = "txtBegDt"
Me.txtBegDt.Size = New System.Drawing.Size(116, 32)
Me.txtBegDt.TabIndex = 5
Me.txtBegDt.TextBox_Text = Nothing
'
'Label3
'
Me.Label3.Location = New System.Drawing.Point(336, 80)
Me.Label3.Name = "Label3"
Me.Label3.Size = New System.Drawing.Size(48, 23)
Me.Label3.TabIndex = 6
Me.Label3.Text = "To Date"
'
'txtEndDt
'
Me.txtEndDt.DateName = "EndDt"
Me.txtEndDt.Location = New System.Drawing.Point(416, 72)
Me.txtEndDt.Name = "txtEndDt"
Me.txtEndDt.Size = New System.Drawing.Size(116, 32)
Me.txtEndDt.TabIndex = 7
Me.txtEndDt.TextBox_Text = Nothing
'
'ErrorProvider1
'
Me.ErrorProvider1.ContainerControl = Me
'
'DataGrid1
'
Me.DataGrid1.DataMember = ""
Me.DataGrid1.HeaderForeColor = System.Drawing.SystemColors.ControlText
Me.DataGrid1.Location = New System.Drawing.Point(64, 160)
Me.DataGrid1.Name = "DataGrid1"
Me.DataGrid1.Size = New System.Drawing.Size(536, 144)
Me.DataGrid1.TabIndex = 8
'
'Label4
'
Me.Label4.Location = New System.Drawing.Point(64, 136)
Me.Label4.Name = "Label4"
Me.Label4.Size = New System.Drawing.Size(128, 16)
Me.Label4.TabIndex = 9
Me.Label4.Text = "Payable Items Not In GL"
'
'cmdDoSerach
'
Me.cmdDoSerach.Location = New System.Drawing.Point(136, 344)
Me.cmdDoSerach.Name = "cmdDoSerach"
Me.cmdDoSerach.Size = New System.Drawing.Size(112, 24)
Me.cmdDoSerach.TabIndex = 10
Me.cmdDoSerach.Text = "Perform Search"
'
'cmdReturn
'
Me.cmdReturn.Location = New System.Drawing.Point(360, 344)
Me.cmdReturn.Name = "cmdReturn"
Me.cmdReturn.Size = New System.Drawing.Size(128, 24)
Me.cmdReturn.TabIndex = 11
Me.cmdReturn.Text = "Return"
'
'OdbcDataAdapter1
'
Me.OdbcDataAdapter1.InsertCommand = Me.OdbcInsertCommand1
Me.OdbcDataAdapter1.SelectCommand = Me.OdbcSelectCommand1
Me.OdbcDataAdapter1.TableMappings.AddRange(New System.Data.Common.DataTableMapping() 
{New System.Data.Common.DataTableMapping("Table", "AMH", 
New System.Data.Common.DataColumnMapping() 
{New System.Data.Common.DataColumnMapping("AMHVND", "AMHVND"), 
New System.Data.Common.DataColumnMapping("AMHBNK", "AMHBNK")})})
'
'OdbcInsertCommand1
'
Me.OdbcInsertCommand1.CommandText = "INSERT INTO BPCSFV60.AMH(AMHVND, AMHBNK) 
VALUES (?, ?)"
Me.OdbcInsertCommand1.Connection = Me.OdbcConnection1
Me.OdbcInsertCommand1.Parameters.Add(New System.Data.Odbc.OdbcParameter("AMHVND", System.Data.Odbc.OdbcType.Decimal, 0, 
System.Data.ParameterDirection.Input, 
False, CType(5, Byte), CType(0, Byte), "AMHVND", 
System.Data.DataRowVersion.Current, Nothing))
Me.OdbcInsertCommand1.Parameters.Add
(New System.Data.Odbc.OdbcParameter
("AMHBNK", System.Data.Odbc.OdbcType.VarChar, 3, "AMHBNK"))
'
'OdbcConnection1
'
Me.OdbcConnection1.ConnectionString = "SORTTABLE=;TRACEFILENAME=;DSN=BPCS 620 
Files;XLATEDLL=;PKG={QGPL/DEFAULT(IBM),2,0" & _
",1,0,512};DBQ=QGPL BPCSFV60 ;SYSTEM=EIM620.EIMNET.COM;QAQQINILIB=;TRANSLATE=1;SQ" & _
"DIAGCODE=;DATABASE=;UID=HERNANDJ; PWD=SANDRA;"
'
'OdbcSelectCommand1
'
Me.OdbcSelectCommand1.CommandText = "SELECT AMHVND, AMHBNK FROM BPCSFV60.AMH"
Me.OdbcSelectCommand1.Connection = Me.OdbcConnection1
'
'DataSet12
'
Me.DataSet12.DataSetName = "DataSet1"
Me.DataSet12.Locale = New System.Globalization.CultureInfo("en-US")
'
'APNotInGL
'
Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)
Me.ClientSize = New System.Drawing.Size(656, 382)
Me.Controls.Add(Me.cmdReturn)
Me.Controls.Add(Me.cmdDoSerach)
Me.Controls.Add(Me.Label4)
Me.Controls.Add(Me.DataGrid1)
Me.Controls.Add(Me.txtEndDt)
Me.Controls.Add(Me.Label3)
Me.Controls.Add(Me.txtBegDt)
Me.Controls.Add(Me.Label2)
Me.Controls.Add(Me.lblDateRange)
Me.Controls.Add(Me.lblDate)
Me.Controls.Add(Me.Label1)
Me.Name = "APNotInGL"
Me.Text = "AP Items Not in GL"
Me.WindowState = System.Windows.Forms.FormWindowState.Maximized
CType(Me.DataGrid1, System.ComponentModel.ISupportInitialize).EndInit()
CType(Me.DataSet12, System.ComponentModel.ISupportInitialize).EndInit()
Me.ResumeLayout(False)
EndSub
#EndRegion
PrivateSub APNotInGL_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) 
HandlesMyBase.Load
Me.lblDate.Text = Now.ToString
EndSub
PrivateSub cmdDoSerach_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) 
Handles cmdDoSerach.Click
ErrorProvider1.SetError(Me.txtBegDt, "")
ErrorProvider1.SetError(Me.txtEndDt, "")
DataSet11.Clear() <===========================error here
Dim OnHand AsDouble
Dim StdCost AsDouble
Dim WBegDt AsDate
Dim WEndDt AsDate
IfMe.txtBegDt.TextBox_Text = "" Then
ErrorProvider1.SetError(Me.txtBegDt, "Valid Beg Date Required")
txtBegDt.Focus()
ExitSub
EndIf
IfMe.txtEndDt.TextBox_Text = "" Then
ErrorProvider1.SetError(Me.txtEndDt, "Valid End Date Required")
txtEndDt.Focus()
ExitSub
EndIf
Try
WBegDt = Convert.ToDateTime(Me.txtBegDt.TextBox_Text)
If IsDate(WBegDt) = FalseThen
ErrorProvider1.SetError(Me.txtBegDt, "Valid Beg Date Required")
txtBegDt.Focus()
ExitSub
EndIf
Catch ex As System.FormatException
ErrorProvider1.SetError(Me.txtBegDt, "Invalid Beg Date")
txtBegDt.Focus()
ExitSub
EndTry
Try
WEndDt = Convert.ToDateTime(Me.txtEndDt.TextBox_Text)
Catch ex As System.FormatException
ErrorProvider1.SetError(Me.txtEndDt, "Invalid End Date")
txtEndDt.Focus()
ExitSub
EndTry
If IsDate(WEndDt) = FalseThen
ErrorProvider1.SetError(Me.txtEndDt, "Valid End Date Required")
txtEndDt.Focus()
ExitSub
EndIf
If WBegDt > WEndDt Then
ErrorProvider1.SetError(Me.txtEndDt, "Beg Date AFter End Date")
txtEndDt.Focus()
ExitSub
EndIf
Dim SqlString AsString
SqlString = "Select * from BPCSFV60.APHL01"
'SqlString = "SELECT BPCSFV60_APHL01.APVNDR, BPCSFV60_AVML01.VNDNAM, "
'SqlString = SqlString & "BPCSFV60_APHL01.APINV, BPCSFV60_APHL01.APHPND, 
BPCSFV60_APHL01.AINVDT, "
'SqlString = SqlString & "BPCSFV60_APHL01.ADUEDT, BPCSFV60_APHL01.APCINA, "
'SqlString = SqlString & " BPCSFV60_GXRL01.XRHVND, BPCSFV60_GXRL01.XRINV INTO 
tblPaymentNotInGL"
'SqlString = SqlString & " FROM (BPCSFV60_APHL01 INNER JOIN BPCSFV60_AVML01 "
'SqlString = SqlString & " ON BPCSFV60_APHL01.APVNDR = BPCSFV60_AVML01.VENDOR) "
'SqlString = SqlString & "INNER JOIN BPCSFV60_GXRL01 ON (BPCSFV60_APHL01.APCMPY = "
'SqlString = SqlString & "BPCSFV60_GXRL01.XRCMPY) AND (BPCSFV60_APHL01.APVNDR = "
'SqlString = SqlString & "BPCSFV60_GXRL01.XRHVND) AND (BPCSFV60_APHL01.APINV = "
'SqlString = SqlString & " BPCSFV60_GXRL01.XRINV) "
''SqlString = SqlString & "WHERE (((BPCSFV60_GXRL01.XRHVND) Is Null) "
''SqlString = SqlString & "AND ((BPCSFV60_GXRL01.XRINV) Is Null));"
OdbcDataAdapter1.SelectCommand.CommandText = SqlString
OdbcDataAdapter1.Fill(DataSet11, "tblPaymentsNotInGL")
EndSub
PrivateSub cmdReturn_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) 
Handles cmdReturn.Click
Form.ActiveForm.Close()
EndSub
PrivateSub OdbcDataAdapter1_RowUpdated
(ByVal sender As System.Object, 
ByVal e As System.Data.Odbc.OdbcRowUpdatedEventArgs)
EndSub
PrivateSub OdbcConnection1_InfoMessage
(ByVal sender As System.Object, 
ByVal e As System.Data.Odbc.OdbcInfoMessageEventArgs) 
Handles OdbcConnection1.InfoMessage
EndSub
PrivateSub OdbcDataAdapter1_RowUpdated_1
(ByVal sender As System.Object, 
ByVal e As System.Data.Odbc.OdbcRowUpdatedEventArgs) 
Handles OdbcDataAdapter1.RowUpdated
EndSub
EndClass
 
Last edited by a moderator:
Dataset11 hasn't been declared with the 'New' keyword whereas dataset12 has....
VB.NET:
Me.DataSet12 = New EIMReconStart.DataSet1

That is why you are getting that exception.....
 
In your cmdDoSearch sub below you are getting the error on the Dataset11.clear line i've looked throught the generated code and i can't find anywhere that Dataset11 has been declared a

VB.NET:
New dataset

This seems strange as it looks as though it has been generated in the designer. Just below the windows forms generated bit add the following line..

VB.NET:
Me.Dataset11 = New System.Data.Dataset

I think that will cure that particular problem, though it still baffles me that it wasn't added by the designer. Have you added this dataset yourself in code?
 
Back
Top