but just can't see what is causing it!
The error occors on the FOR line!
I would really appritiate any advice.
Thanks
...:: ERROR
Object reference not set to an instance of an object.
...:: CODE
Function GetSelectedIndex(ByVal OID As String) As Integer
Dim iLoop As Integer
Dim dt As DataTable = ddlDataSet.Tables("Offices")
For iLoop = 0 To dt.Rows.Count - 1
If Int32.Parse(OID) = Int32.Parse(dt.Rows(iLoop)("officeID")) Then
Return iLoop
End If
Next iLoop
End Functiondt is null/nothing . ddDAtaSet.Tables("Offices") mustn't be a valid name
for a table. Consider simply trying by # for now, like
ddDataSet.Tables(0) and see if that works.
Karl
--
MY ASP.Net tutorials
http://www.openmymind.net/
"Tim::.." <myatix_at_hotmail.com> wrote in message
news:F918E072-B5BA-42AF-865E-CE4DAD105C91@.microsoft.com...
> I keep getting the following error! I'm sure it is a really simple problem
> but just can't see what is causing it!
> The error occors on the FOR line!
> I would really appritiate any advice.
> Thanks
>
> ..:: ERROR
> Object reference not set to an instance of an object.
> ..:: CODE
> Function GetSelectedIndex(ByVal OID As String) As Integer
> Dim iLoop As Integer
> Dim dt As DataTable = ddlDataSet.Tables("Offices")
> For iLoop = 0 To dt.Rows.Count - 1
> If Int32.Parse(OID) = Int32.Parse(dt.Rows(iLoop)("officeID"))
Then
> Return iLoop
> End If
> Next iLoop
> End Function
Are you sure ddlDataSet contains table Offices?
Eliyahu
"Tim::.." <myatix_at_hotmail.com> wrote in message
news:F918E072-B5BA-42AF-865E-CE4DAD105C91@.microsoft.com...
> I keep getting the following error! I'm sure it is a really simple problem
> but just can't see what is causing it!
> The error occors on the FOR line!
> I would really appritiate any advice.
> Thanks
>
> ..:: ERROR
> Object reference not set to an instance of an object.
> ..:: CODE
> Function GetSelectedIndex(ByVal OID As String) As Integer
> Dim iLoop As Integer
> Dim dt As DataTable = ddlDataSet.Tables("Offices")
> For iLoop = 0 To dt.Rows.Count - 1
> If Int32.Parse(OID) = Int32.Parse(dt.Rows(iLoop)("officeID"))
Then
> Return iLoop
> End If
> Next iLoop
> End Function
As far as I can see right now it looks fine!
Here is the code that creates the dataset! What else could be wrong?
Thanks
Function GetCategories() As DataSet
'Populate the ddlDataSet
Dim Myconn As New SqlConnection(ConfigurationSettings.AppSettings("strConn"))
Dim myDataAdapter As SqlDataAdapter = New SqlDataAdapter("SelectOffice",
Myconn)
myDataAdapter.Fill(ddlDataSet, "Offices")
Return ddlDataSet
End Function
"Eliyahu Goldin" wrote:
> Are you sure ddlDataSet contains table Offices?
> Eliyahu
> "Tim::.." <myatix_at_hotmail.com> wrote in message
> news:F918E072-B5BA-42AF-865E-CE4DAD105C91@.microsoft.com...
> > I keep getting the following error! I'm sure it is a really simple problem
> > but just can't see what is causing it!
> > The error occors on the FOR line!
> > I would really appritiate any advice.
> > Thanks
> > ..:: ERROR
> > Object reference not set to an instance of an object.
> > ..:: CODE
> > Function GetSelectedIndex(ByVal OID As String) As Integer
> > Dim iLoop As Integer
> > Dim dt As DataTable = ddlDataSet.Tables("Offices")
> > For iLoop = 0 To dt.Rows.Count - 1
> > If Int32.Parse(OID) = Int32.Parse(dt.Rows(iLoop)("officeID"))
> Then
> > Return iLoop
> > End If
> > Next iLoop
> > End Function
>
Like I said, try to access if via ddlDataSet.Tables(0)
also try to check the value of ddlDataSet.Tables(0).TableName which might
help you see the problem.
I assume in your GetSelectedIndex function ddlDataSet is some member-level
variable, since it isn't passed into the function...
Karl
--
MY ASP.Net tutorials
http://www.openmymind.net/
"Tim::.." <myatix_at_hotmail.com> wrote in message
news:44347A61-4408-4475-839B-E34115595191@.microsoft.com...
> As far as I can see right now it looks fine!
> Here is the code that creates the dataset! What else could be wrong?
> Thanks
> Function GetCategories() As DataSet
> 'Populate the ddlDataSet
> Dim Myconn As New
SqlConnection(ConfigurationSettings.AppSettings("strConn"))
> Dim myDataAdapter As SqlDataAdapter = New SqlDataAdapter("SelectOffice",
> Myconn)
> myDataAdapter.Fill(ddlDataSet, "Offices")
> Return ddlDataSet
> End Function
>
>
> "Eliyahu Goldin" wrote:
> > Are you sure ddlDataSet contains table Offices?
> > Eliyahu
> > "Tim::.." <myatix_at_hotmail.com> wrote in message
> > news:F918E072-B5BA-42AF-865E-CE4DAD105C91@.microsoft.com...
> > > I keep getting the following error! I'm sure it is a really simple
problem
> > > but just can't see what is causing it!
> > > > The error occors on the FOR line!
> > > > I would really appritiate any advice.
> > > > Thanks
> > > > > > ..:: ERROR
> > > Object reference not set to an instance of an object.
> > > > ..:: CODE
> > > Function GetSelectedIndex(ByVal OID As String) As Integer
> > > Dim iLoop As Integer
> > > Dim dt As DataTable = ddlDataSet.Tables("Offices")
> > > For iLoop = 0 To dt.Rows.Count - 1
> > > If Int32.Parse(OID) =
Int32.Parse(dt.Rows(iLoop)("officeID"))
> > Then
> > > Return iLoop
> > > End If
> > > Next iLoop
> > > > End Function
0 comments:
Post a Comment