Showing posts with label basically. Show all posts
Showing posts with label basically. Show all posts

Wednesday, March 21, 2012

Object reference not set to an instance of an object.

im filling a datset with names of films and need to get the number of
films in the dataset. basically i want to know if its empty. but when
i try and get the number of rows it gives me the error: "Object
reference not set to an instance of an object" . I get this error from
the line:"Label3.Text =
CalendarFilmsDataSet11.Tables("Customers").Rows.Count". and i get the
error whether the dataset has items in it or not. can anyone tell me
why this is happening.
this is my code:

Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load

If Not Page.IsPostBack Then

Label2.Text = "Films Showing on " + Session("theShowDate")

CalendarFilmsDataSet11.Clear()

OdbcDataAdapter1.SelectCommand.Parameters("cinemaID").Value
= Session("theCinemaID")

OdbcDataAdapter1.SelectCommand.Parameters("showDate").Value
= Session("theShowDate")

OdbcDataAdapter1.Fill(CalendarFilmsDataSet11)

Label3.Text =
CalendarFilmsDataSet11.Tables("Customers").Rows.Count

ListBox1.DataBind()

End If

End Subthe correct way to access data in a dataset is to first test using if
statements
if(ds != null && ds.Tables != null && ds.Tables.Count > 0 etc

--
________________________
Warm regards,
Alvin Bruney [MVP ASP.NET]

[Shameless Author plug]
The O.W.C. Black Book with .NET
www.lulu.com/owc, Amazon
Professional VSTO.NET - Wrox/Wiley 2006
-----------------

"bazzer" <somersbar@.yahoo.com> wrote in message
news:1144940392.384018.153860@.e56g2000cwe.googlegr oups.com...
> im filling a datset with names of films and need to get the number of
> films in the dataset. basically i want to know if its empty. but when
> i try and get the number of rows it gives me the error: "Object
> reference not set to an instance of an object" . I get this error from
> the line:"Label3.Text =
> CalendarFilmsDataSet11.Tables("Customers").Rows.Count". and i get the
> error whether the dataset has items in it or not. can anyone tell me
> why this is happening.
> this is my code:
> Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
> System.EventArgs) Handles MyBase.Load
> If Not Page.IsPostBack Then
> Label2.Text = "Films Showing on " + Session("theShowDate")
> CalendarFilmsDataSet11.Clear()
> OdbcDataAdapter1.SelectCommand.Parameters("cinemaID").Value
> = Session("theCinemaID")
> OdbcDataAdapter1.SelectCommand.Parameters("showDate").Value
> = Session("theShowDate")
> OdbcDataAdapter1.Fill(CalendarFilmsDataSet11)
> Label3.Text =
> CalendarFilmsDataSet11.Tables("Customers").Rows.Count
> ListBox1.DataBind()
> End If
> End Sub
On Thu, 13 Apr 2006 11:26:47 -0400, Alvin Bruney wrote:

> the correct way to access data in a dataset is to first test using if
> statements
> if(ds != null && ds.Tables != null && ds.Tables.Count > 0 etc

Or, in VB, as the original author seems to be using

If not ds is Nothing AndAlso not ds.Tables is Nothing AndAlso
ds.Tables.Count > 0 ...
right. 2.0 also gives VB the IsNot function as well
If ds IsNot Nothing

I'm not aware if there is a performance improvement though.
--
________________________
Warm regards,
Alvin Bruney [MVP ASP.NET]

[Shameless Author plug]
The O.W.C. Black Book with .NET
www.lulu.com/owc, Amazon
Professional VSTO.NET - Wrox/Wiley 2006
-----------------

"Erik Funkenbusch" <erik@.despam-funkenbusch.com> wrote in message
news:1lsvaw55khggs.dlg@.funkenbusch.com...
> On Thu, 13 Apr 2006 11:26:47 -0400, Alvin Bruney wrote:
>> the correct way to access data in a dataset is to first test using if
>> statements
>> if(ds != null && ds.Tables != null && ds.Tables.Count > 0 etc
> Or, in VB, as the original author seems to be using
> If not ds is Nothing AndAlso not ds.Tables is Nothing AndAlso
> ds.Tables.Count > 0 ...

Friday, March 16, 2012

Object reference not set to an instance of an object.

im filling a datset with names of films and need to get the number of
films in the dataset. basically i want to know if its empty. but when
i try and get the number of rows it gives me the error: "Object
reference not set to an instance of an object" . I get this error from
the line:"Label3.Text =
CalendarFilmsDataSet11.Tables("Customers").Rows.Count". and i get the
error whether the dataset has items in it or not. can anyone tell me
why this is happening.
this is my code:
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
If Not Page.IsPostBack Then
Label2.Text = "Films Showing on " + Session("theShowDate")
CalendarFilmsDataSet11.Clear()
OdbcDataAdapter1.SelectCommand.Parameters("cinemaID").Value
= Session("theCinemaID")
OdbcDataAdapter1.SelectCommand.Parameters("showDate").Value
= Session("theShowDate")
OdbcDataAdapter1.Fill(CalendarFilmsDataSet11)
Label3.Text =
CalendarFilmsDataSet11.Tables("Customers").Rows.Count
ListBox1.DataBind()
End If
End Subthe correct way to access data in a dataset is to first test using if
statements
if(ds != null && ds.Tables != null && ds.Tables.Count > 0 etc
________________________
Warm regards,
Alvin Bruney [MVP ASP.NET]
[Shameless Author plug]
The O.W.C. Black Book with .NET
www.lulu.com/owc, Amazon
Professional VSTO.NET - Wrox/Wiley 2006
----
"bazzer" <somersbar@.yahoo.com> wrote in message
news:1144940392.384018.153860@.e56g2000cwe.googlegroups.com...
> im filling a datset with names of films and need to get the number of
> films in the dataset. basically i want to know if its empty. but when
> i try and get the number of rows it gives me the error: "Object
> reference not set to an instance of an object" . I get this error from
> the line:"Label3.Text =
> CalendarFilmsDataSet11.Tables("Customers").Rows.Count". and i get the
> error whether the dataset has items in it or not. can anyone tell me
> why this is happening.
> this is my code:
> Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
> System.EventArgs) Handles MyBase.Load
> If Not Page.IsPostBack Then
> Label2.Text = "Films Showing on " + Session("theShowDate")
> CalendarFilmsDataSet11.Clear()
> OdbcDataAdapter1.SelectCommand.Parameters("cinemaID").Value
> = Session("theCinemaID")
> OdbcDataAdapter1.SelectCommand.Parameters("showDate").Value
> = Session("theShowDate")
> OdbcDataAdapter1.Fill(CalendarFilmsDataSet11)
> Label3.Text =
> CalendarFilmsDataSet11.Tables("Customers").Rows.Count
> ListBox1.DataBind()
> End If
> End Sub
>
On Thu, 13 Apr 2006 11:26:47 -0400, Alvin Bruney wrote:

> the correct way to access data in a dataset is to first test using if
> statements
> if(ds != null && ds.Tables != null && ds.Tables.Count > 0 etc
Or, in VB, as the original author seems to be using
If not ds is Nothing AndAlso not ds.Tables is Nothing AndAlso
ds.Tables.Count > 0 ...
right. 2.0 also gives VB the IsNot function as well
If ds IsNot Nothing
I'm not aware if there is a performance improvement though.
--
________________________
Warm regards,
Alvin Bruney [MVP ASP.NET]
[Shameless Author plug]
The O.W.C. Black Book with .NET
www.lulu.com/owc, Amazon
Professional VSTO.NET - Wrox/Wiley 2006
----
"Erik Funkenbusch" <erik@.despam-funkenbusch.com> wrote in message
news:1lsvaw55khggs.dlg@.funkenbusch.com...
> On Thu, 13 Apr 2006 11:26:47 -0400, Alvin Bruney wrote:
>
> Or, in VB, as the original author seems to be using
> If not ds is Nothing AndAlso not ds.Tables is Nothing AndAlso
> ds.Tables.Count > 0 ...