By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
446,257 Members | 1,294 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 446,257 IT Pros & Developers. It's quick & easy.

sqlDataReader not returning records when called inside class

P: n/a
I have a funtion that works fine and dandy when called from anywhere in my
app. It will NOT work when called from inside the class in which it resides.

This is the function I'm calling: "getProductByID(productID)" from inside
another method in the same class. See below.

This line throws a null ref exception:
While dr.Read()

Thanks for any insight!

Public Sub deleteProduct(ByVal productID)

'Set up parameters
Dim arParms(0) As SqlParameter
arParms(0) = New SqlParameter("@productID",
SqlDbType.UniqueIdentifier)
arParms(0).Value = productID

'get the images to delete
Dim context As System.Web.HttpContext = System.Web.HttpContext.Current
Dim dr As SqlDataReader = getProductByID(productID)

Dim thumbImg As String
Dim fullImg As String

While dr.Read()
'delete thumb
fullImg = context.Application("webRoot") &
"vendorImages/" & dr.Item("galleryFolder").ToString & "/" &
dr.Item("imageFull").ToString
fullImg = context.Current.Server.MapPath(fullImg)
Dim thisImgFull As New System.IO.FileInfo(fullImg)
thisImgFull.Delete()
End While
.... omitted for brevity
End Sub
Nov 18 '05 #1
Share this Question
Share on Google+
8 Replies


P: n/a
Hi,

Try:

Dim dr As New SqlDataReader = getProductByID(productID)

Also make sure that productID actually holds what you want it to when you
pass it. Here:

Public Sub deleteProduct(ByVal productID)

You are not giving it a type, should it be an Integer? Good luck! Ken.

--
Ken Dopierala Jr.
For great ASP.Net web hosting try:
http://www.webhost4life.com/default.asp?refid=Spinlight
If you sign up under me and need help, email me.

"bidllc" <bi****@discussions.microsoft.com> wrote in message
news:10**********************************@microsof t.com...
I have a funtion that works fine and dandy when called from anywhere in my
app. It will NOT work when called from inside the class in which it resides.
This is the function I'm calling: "getProductByID(productID)" from inside
another method in the same class. See below.

This line throws a null ref exception:
While dr.Read()

Thanks for any insight!

Public Sub deleteProduct(ByVal productID)

'Set up parameters
Dim arParms(0) As SqlParameter
arParms(0) = New SqlParameter("@productID",
SqlDbType.UniqueIdentifier)
arParms(0).Value = productID

'get the images to delete
Dim context As System.Web.HttpContext = System.Web.HttpContext.Current

Dim dr As SqlDataReader = getProductByID(productID)

Dim thumbImg As String
Dim fullImg As String

While dr.Read()
'delete thumb
fullImg = context.Application("webRoot") &
"vendorImages/" & dr.Item("galleryFolder").ToString & "/" &
dr.Item("imageFull").ToString
fullImg = context.Current.Server.MapPath(fullImg)
Dim thisImgFull As New System.IO.FileInfo(fullImg)
thisImgFull.Delete()
End While
... omitted for brevity
End Sub

Nov 18 '05 #2

P: n/a
HI Ken, thanks for the reply. productID is a uniqueidentifier and it's
definitely coming in, I've double checked that. I also tried your
suggestiond, but no go. :(

"Ken Dopierala Jr." wrote:
Hi,

Try:

Dim dr As New SqlDataReader = getProductByID(productID)

Also make sure that productID actually holds what you want it to when you
pass it. Here:

Public Sub deleteProduct(ByVal productID)

You are not giving it a type, should it be an Integer? Good luck! Ken.

--
Ken Dopierala Jr.
For great ASP.Net web hosting try:
http://www.webhost4life.com/default.asp?refid=Spinlight
If you sign up under me and need help, email me.

"bidllc" <bi****@discussions.microsoft.com> wrote in message
news:10**********************************@microsof t.com...
I have a funtion that works fine and dandy when called from anywhere in my
app. It will NOT work when called from inside the class in which it

resides.

This is the function I'm calling: "getProductByID(productID)" from inside
another method in the same class. See below.

This line throws a null ref exception:
While dr.Read()

Thanks for any insight!

Public Sub deleteProduct(ByVal productID)

'Set up parameters
Dim arParms(0) As SqlParameter
arParms(0) = New SqlParameter("@productID",
SqlDbType.UniqueIdentifier)
arParms(0).Value = productID

'get the images to delete
Dim context As System.Web.HttpContext =

System.Web.HttpContext.Current


Dim dr As SqlDataReader = getProductByID(productID)

Dim thumbImg As String
Dim fullImg As String

While dr.Read()
'delete thumb
fullImg = context.Application("webRoot") &
"vendorImages/" & dr.Item("galleryFolder").ToString & "/" &
dr.Item("imageFull").ToString
fullImg = context.Current.Server.MapPath(fullImg)
Dim thisImgFull As New System.IO.FileInfo(fullImg)
thisImgFull.Delete()
End While
... omitted for brevity
End Sub


Nov 18 '05 #3

P: n/a
Hi,

The problem is that dr is Nothing which means that for some reason your
getProductByID() is returning nothing instead of a data reader. I would
step through the code and make sure that getProductByID() is passing back a
valid data reader when called from your delete function. Also make sure the
data reader isn't being closed or going out of scope before you pass it
back. Can you post your getProductByID() function code and also tell what
the relationship between that and the delete function are code wise? I mean
are they in the same module or different classes. We need to find out why
Nothing is return by getProductByID() when called from the delete function
and not from other code in your solution. Ken.

--
Ken Dopierala Jr.
For great ASP.Net web hosting try:
http://www.webhost4life.com/default.asp?refid=Spinlight
If you sign up under me and need help, email me.

"bidllc" <bi****@discussions.microsoft.com> wrote in message
news:86**********************************@microsof t.com...
HI Ken, thanks for the reply. productID is a uniqueidentifier and it's
definitely coming in, I've double checked that. I also tried your
suggestiond, but no go. :(

"Ken Dopierala Jr." wrote:
Hi,

Try:

Dim dr As New SqlDataReader = getProductByID(productID)

Also make sure that productID actually holds what you want it to when you pass it. Here:

Public Sub deleteProduct(ByVal productID)

You are not giving it a type, should it be an Integer? Good luck! Ken.

--
Ken Dopierala Jr.
For great ASP.Net web hosting try:
http://www.webhost4life.com/default.asp?refid=Spinlight
If you sign up under me and need help, email me.

"bidllc" <bi****@discussions.microsoft.com> wrote in message
news:10**********************************@microsof t.com...
I have a funtion that works fine and dandy when called from anywhere in my app. It will NOT work when called from inside the class in which it

resides.

This is the function I'm calling: "getProductByID(productID)" from inside another method in the same class. See below.

This line throws a null ref exception:
While dr.Read()

Thanks for any insight!

Public Sub deleteProduct(ByVal productID)

'Set up parameters
Dim arParms(0) As SqlParameter
arParms(0) = New SqlParameter("@productID",
SqlDbType.UniqueIdentifier)
arParms(0).Value = productID

'get the images to delete
Dim context As System.Web.HttpContext =

System.Web.HttpContext.Current


Dim dr As SqlDataReader = getProductByID(productID)

Dim thumbImg As String
Dim fullImg As String

While dr.Read()
'delete thumb
fullImg = context.Application("webRoot") &
"vendorImages/" & dr.Item("galleryFolder").ToString & "/" &
dr.Item("imageFull").ToString
fullImg = context.Current.Server.MapPath(fullImg)
Dim thisImgFull As New System.IO.FileInfo(fullImg)
thisImgFull.Delete()
End While
... omitted for brevity
End Sub


Nov 18 '05 #4

P: n/a
Here's the getProductByID function. And the two methods are in the same
class. It's definitely not returning a valid sqlDatareader, just don't know
why that is.

thanks.

Public Function getProductByID(ByVal productID) As SqlDataReader

'Set up parameters
Dim arParms(0) As SqlParameter
arParms(0) = New SqlParameter("@productID",
SqlDbType.UniqueIdentifier)
arParms(0).Value = productID
'insert the data
Dim dr As SqlDataReader = SqlHelper.ExecuteReader(connStr,
CommandType.StoredProcedure, "productByIDGet", arParms)
Return dr

End Function


"Ken Dopierala Jr." wrote:
Hi,

The problem is that dr is Nothing which means that for some reason your
getProductByID() is returning nothing instead of a data reader. I would
step through the code and make sure that getProductByID() is passing back a
valid data reader when called from your delete function. Also make sure the
data reader isn't being closed or going out of scope before you pass it
back. Can you post your getProductByID() function code and also tell what
the relationship between that and the delete function are code wise? I mean
are they in the same module or different classes. We need to find out why
Nothing is return by getProductByID() when called from the delete function
and not from other code in your solution. Ken.

--
Ken Dopierala Jr.
For great ASP.Net web hosting try:
http://www.webhost4life.com/default.asp?refid=Spinlight
If you sign up under me and need help, email me.

"bidllc" <bi****@discussions.microsoft.com> wrote in message
news:86**********************************@microsof t.com...
HI Ken, thanks for the reply. productID is a uniqueidentifier and it's
definitely coming in, I've double checked that. I also tried your
suggestiond, but no go. :(

"Ken Dopierala Jr." wrote:
Hi,

Try:

Dim dr As New SqlDataReader = getProductByID(productID)

Also make sure that productID actually holds what you want it to when you pass it. Here:

Public Sub deleteProduct(ByVal productID)

You are not giving it a type, should it be an Integer? Good luck! Ken.

--
Ken Dopierala Jr.
For great ASP.Net web hosting try:
http://www.webhost4life.com/default.asp?refid=Spinlight
If you sign up under me and need help, email me.

"bidllc" <bi****@discussions.microsoft.com> wrote in message
news:10**********************************@microsof t.com...
> I have a funtion that works fine and dandy when called from anywhere in my > app. It will NOT work when called from inside the class in which it
resides.
>
> This is the function I'm calling: "getProductByID(productID)" from inside > another method in the same class. See below.
>
> This line throws a null ref exception:
> While dr.Read()
>
> Thanks for any insight!
>
>
>
> Public Sub deleteProduct(ByVal productID)
>
> 'Set up parameters
> Dim arParms(0) As SqlParameter
> arParms(0) = New SqlParameter("@productID",
> SqlDbType.UniqueIdentifier)
> arParms(0).Value = productID
>
> 'get the images to delete
> Dim context As System.Web.HttpContext =
System.Web.HttpContext.Current
>
>
> Dim dr As SqlDataReader = getProductByID(productID)
>
> Dim thumbImg As String
> Dim fullImg As String
>
> While dr.Read()
> 'delete thumb
> fullImg = context.Application("webRoot") &
> "vendorImages/" & dr.Item("galleryFolder").ToString & "/" &
> dr.Item("imageFull").ToString
> fullImg = context.Current.Server.MapPath(fullImg)
> Dim thisImgFull As New System.IO.FileInfo(fullImg)
> thisImgFull.Delete()
> End While
>
>
> ... omitted for brevity
>
>
> End Sub


Nov 18 '05 #5

P: n/a
I can' tell why it isn't working. You could put a breakpoint on the Return
dr line. Then call this code from where it works in your code and also from
where it doesn't. If dr is valid at the breakpoint for one call and Nothing
for another then the problem has to be at what you are passing in. Also you
might want to put the New keyword in your Dim dr As SqlDataReader = ....
line below. Good luck! Ken.

"bidllc" <bi****@discussions.microsoft.com> wrote in message
news:32**********************************@microsof t.com...
Here's the getProductByID function. And the two methods are in the same
class. It's definitely not returning a valid sqlDatareader, just don't know why that is.

thanks.

Public Function getProductByID(ByVal productID) As SqlDataReader

'Set up parameters
Dim arParms(0) As SqlParameter
arParms(0) = New SqlParameter("@productID",
SqlDbType.UniqueIdentifier)
arParms(0).Value = productID
'insert the data
Dim dr As SqlDataReader = SqlHelper.ExecuteReader(connStr,
CommandType.StoredProcedure, "productByIDGet", arParms)
Return dr

End Function


"Ken Dopierala Jr." wrote:
Hi,

The problem is that dr is Nothing which means that for some reason your
getProductByID() is returning nothing instead of a data reader. I would
step through the code and make sure that getProductByID() is passing back a valid data reader when called from your delete function. Also make sure the data reader isn't being closed or going out of scope before you pass it
back. Can you post your getProductByID() function code and also tell what the relationship between that and the delete function are code wise? I mean are they in the same module or different classes. We need to find out why Nothing is return by getProductByID() when called from the delete function and not from other code in your solution. Ken.

--
Ken Dopierala Jr.
For great ASP.Net web hosting try:
http://www.webhost4life.com/default.asp?refid=Spinlight
If you sign up under me and need help, email me.

"bidllc" <bi****@discussions.microsoft.com> wrote in message
news:86**********************************@microsof t.com...
HI Ken, thanks for the reply. productID is a uniqueidentifier and it's definitely coming in, I've double checked that. I also tried your
suggestiond, but no go. :(

"Ken Dopierala Jr." wrote:

> Hi,
>
> Try:
>
> Dim dr As New SqlDataReader = getProductByID(productID)
>
> Also make sure that productID actually holds what you want it to when
you
> pass it. Here:
>
> Public Sub deleteProduct(ByVal productID)
>
> You are not giving it a type, should it be an Integer? Good luck!
Ken. >
> --
> Ken Dopierala Jr.
> For great ASP.Net web hosting try:
> http://www.webhost4life.com/default.asp?refid=Spinlight
> If you sign up under me and need help, email me.
>
> "bidllc" <bi****@discussions.microsoft.com> wrote in message
> news:10**********************************@microsof t.com...
> > I have a funtion that works fine and dandy when called from anywhere in my
> > app. It will NOT work when called from inside the class in which

it > resides.
> >
> > This is the function I'm calling: "getProductByID(productID)" from

inside
> > another method in the same class. See below.
> >
> > This line throws a null ref exception:
> > While dr.Read()
> >
> > Thanks for any insight!
> >
> >
> >
> > Public Sub deleteProduct(ByVal productID)
> >
> > 'Set up parameters
> > Dim arParms(0) As SqlParameter
> > arParms(0) = New SqlParameter("@productID",
> > SqlDbType.UniqueIdentifier)
> > arParms(0).Value = productID
> >
> > 'get the images to delete
> > Dim context As System.Web.HttpContext =
> System.Web.HttpContext.Current
> >
> >
> > Dim dr As SqlDataReader = getProductByID(productID)
> >
> > Dim thumbImg As String
> > Dim fullImg As String
> >
> > While dr.Read()
> > 'delete thumb
> > fullImg = context.Application("webRoot") &
> > "vendorImages/" & dr.Item("galleryFolder").ToString & "/" &
> > dr.Item("imageFull").ToString
> > fullImg = context.Current.Server.MapPath(fullImg) > > Dim thisImgFull As New System.IO.FileInfo(fullImg) > > thisImgFull.Delete()
> > End While
> >
> >
> > ... omitted for brevity
> >
> >
> > End Sub
>
>
>


Nov 18 '05 #6

P: n/a
2 pennies - is connStr actually declared and initialised ?
I have a funtion that works fine and dandy when called from anywhere in my
app. It will NOT work when called from inside the class in which it resides.

This is the function I'm calling: "getProductByID(productID)" from inside
another method in the same class. See below.

This line throws a null ref exception:
While dr.Read()

Thanks for any insight!

Public Sub deleteProduct(ByVal productID)

'Set up parameters
Dim arParms(0) As SqlParameter
arParms(0) = New SqlParameter("@productID",
SqlDbType.UniqueIdentifier)
arParms(0).Value = productID

'get the images to delete
Dim context As System.Web.HttpContext = System.Web.HttpContext.Current
Dim dr As SqlDataReader = getProductByID(productID)

Dim thumbImg As String
Dim fullImg As String

While dr.Read()
'delete thumb
fullImg = context.Application("webRoot") &
"vendorImages/" & dr.Item("galleryFolder").ToString & "/" &
dr.Item("imageFull").ToString
fullImg = context.Current.Server.MapPath(fullImg)
Dim thisImgFull As New System.IO.FileInfo(fullImg)
thisImgFull.Delete()
End While
.... omitted for brevity
End Su


User submitted from AEWNET (http://www.aewnet.com/)
Nov 18 '05 #7

P: n/a
yup...

"Guest" wrote:
2 pennies - is connStr actually declared and initialised ?
I have a funtion that works fine and dandy when called from anywhere in my
app. It will NOT work when called from inside the class in which it resides.

This is the function I'm calling: "getProductByID(productID)" from inside
another method in the same class. See below.

This line throws a null ref exception:
While dr.Read()

Thanks for any insight!

Public Sub deleteProduct(ByVal productID)

'Set up parameters
Dim arParms(0) As SqlParameter
arParms(0) = New SqlParameter("@productID",
SqlDbType.UniqueIdentifier)
arParms(0).Value = productID

'get the images to delete
Dim context As System.Web.HttpContext = System.Web.HttpContext.Current
Dim dr As SqlDataReader = getProductByID(productID)

Dim thumbImg As String
Dim fullImg As String

While dr.Read()
'delete thumb
fullImg = context.Application("webRoot") &
"vendorImages/" & dr.Item("galleryFolder").ToString & "/" &
dr.Item("imageFull").ToString
fullImg = context.Current.Server.MapPath(fullImg)
Dim thisImgFull As New System.IO.FileInfo(fullImg)
thisImgFull.Delete()
End While
.... omitted for brevity
End Sub


User submitted from AEWNET (http://www.aewnet.com/)

Nov 18 '05 #8

P: n/a
I know, it's very frustrating. I'll keep poking around but I am just
completely stumped. THanks for trying!

"Ken Dopierala Jr." wrote:
I can' tell why it isn't working. You could put a breakpoint on the Return
dr line. Then call this code from where it works in your code and also from
where it doesn't. If dr is valid at the breakpoint for one call and Nothing
for another then the problem has to be at what you are passing in. Also you
might want to put the New keyword in your Dim dr As SqlDataReader = ....
line below. Good luck! Ken.

"bidllc" <bi****@discussions.microsoft.com> wrote in message
news:32**********************************@microsof t.com...
Here's the getProductByID function. And the two methods are in the same
class. It's definitely not returning a valid sqlDatareader, just don't

know
why that is.

thanks.

Public Function getProductByID(ByVal productID) As SqlDataReader

'Set up parameters
Dim arParms(0) As SqlParameter
arParms(0) = New SqlParameter("@productID",
SqlDbType.UniqueIdentifier)
arParms(0).Value = productID
'insert the data
Dim dr As SqlDataReader = SqlHelper.ExecuteReader(connStr,
CommandType.StoredProcedure, "productByIDGet", arParms)
Return dr

End Function


"Ken Dopierala Jr." wrote:
Hi,

The problem is that dr is Nothing which means that for some reason your
getProductByID() is returning nothing instead of a data reader. I would
step through the code and make sure that getProductByID() is passing back a valid data reader when called from your delete function. Also make sure the data reader isn't being closed or going out of scope before you pass it
back. Can you post your getProductByID() function code and also tell what the relationship between that and the delete function are code wise? I mean are they in the same module or different classes. We need to find out why Nothing is return by getProductByID() when called from the delete function and not from other code in your solution. Ken.

--
Ken Dopierala Jr.
For great ASP.Net web hosting try:
http://www.webhost4life.com/default.asp?refid=Spinlight
If you sign up under me and need help, email me.

"bidllc" <bi****@discussions.microsoft.com> wrote in message
news:86**********************************@microsof t.com...
> HI Ken, thanks for the reply. productID is a uniqueidentifier and it's > definitely coming in, I've double checked that. I also tried your
> suggestiond, but no go. :(
>
>
>
> "Ken Dopierala Jr." wrote:
>
> > Hi,
> >
> > Try:
> >
> > Dim dr As New SqlDataReader = getProductByID(productID)
> >
> > Also make sure that productID actually holds what you want it to when you
> > pass it. Here:
> >
> > Public Sub deleteProduct(ByVal productID)
> >
> > You are not giving it a type, should it be an Integer? Good luck! Ken. > >
> > --
> > Ken Dopierala Jr.
> > For great ASP.Net web hosting try:
> > http://www.webhost4life.com/default.asp?refid=Spinlight
> > If you sign up under me and need help, email me.
> >
> > "bidllc" <bi****@discussions.microsoft.com> wrote in message
> > news:10**********************************@microsof t.com...
> > > I have a funtion that works fine and dandy when called from anywhere in my
> > > app. It will NOT work when called from inside the class in which it > > resides.
> > >
> > > This is the function I'm calling: "getProductByID(productID)" from
inside
> > > another method in the same class. See below.
> > >
> > > This line throws a null ref exception:
> > > While dr.Read()
> > >
> > > Thanks for any insight!
> > >
> > >
> > >
> > > Public Sub deleteProduct(ByVal productID)
> > >
> > > 'Set up parameters
> > > Dim arParms(0) As SqlParameter
> > > arParms(0) = New SqlParameter("@productID",
> > > SqlDbType.UniqueIdentifier)
> > > arParms(0).Value = productID
> > >
> > > 'get the images to delete
> > > Dim context As System.Web.HttpContext =
> > System.Web.HttpContext.Current
> > >
> > >
> > > Dim dr As SqlDataReader = getProductByID(productID)
> > >
> > > Dim thumbImg As String
> > > Dim fullImg As String
> > >
> > > While dr.Read()
> > > 'delete thumb
> > > fullImg = context.Application("webRoot") &
> > > "vendorImages/" & dr.Item("galleryFolder").ToString & "/" &
> > > dr.Item("imageFull").ToString
> > > fullImg = context.Current.Server.MapPath(fullImg) > > > Dim thisImgFull As New System.IO.FileInfo(fullImg) > > > thisImgFull.Delete()
> > > End While
> > >
> > >
> > > ... omitted for brevity
> > >
> > >
> > > End Sub
> >
> >
> >


Nov 18 '05 #9

This discussion thread is closed

Replies have been disabled for this discussion.