System.NullReferenceException

tripes

Member
Joined
Apr 16, 2009
Messages
18
Programming Experience
Beginner
hi i am using VB.net 2003 and i am trying to get the number of rows of a dataset from form1 into form2 in order to use it for something else and i am getting the error"System.NullReferenceException occured...Additional information: object reference not set to an instance of an object"...my code is like this:

in form1:
Public x as integer= me.dataset.table.rows.count here it gives me the error

in form2:
dim frm as new form1
msgbox(frm.x)

pls help :(
 
either:

Me.dataset is not set to an instance of an object or
Me.dataset.table is not set to an instance of an object

Rows.Count should always work

-

If you don't understand the phrase "is not set to an instance of an object" then you need to do a little background reading on Object Oriented programming and the difference between these two statements:

Dim dt as DataTable
Dim dt as DataTable = New DataTable()
 
I have the simmilar problem. Cannot make new row in the dataset.

the code is:

Private Sub vpisi_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles vpisi.Click

Dim dsNewRow As DataRow

dsNewRow = ds.Tables("vpis").NewRow()


dsNewRow.Item(0) = CInt(stevilo.Text)

ds.Tables("vpis").Rows.Add(dsNewRow)

da.Update(ds, "vpis")

stevilo.Clear()



End Sub

This is the code from some tutorial. When I run this code I get the message for this line:

dsNewRow = ds.Tables("vpis").NewRow()

"Object reference not set to an instance of an object."

Why that.
Thanks!
 
Back
Top