468,121 Members | 1,477 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 468,121 developers. It's quick & easy.

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

I have a page, where I'm retrieving a file location from a database and
outputting it's contents (HTML) onto a web page.
On the aspx page, I have referred to the code behind it using the line
below. This is where I'm getting the "Object reference not set to an
instance.." error
<% response.writefile(thelink())%>.

The function that line is referring to is below. The record is being
retrieved from the database according to its querystring.

Function thelink() As Object

Dim tow As String

tow = Request.QueryString("tow")

If tow <> "" Then

viewstate("tow") = "@" & tow

CmdIncLink.Parameters.Item("@tow").Value = tow

Dim tow_reader As SqlDataReader

Try

nsqlconnn.Open()

tow_reader = CmdIncLink.ExecuteReader

Do While tow_reader.Read

Return tow_reader("inclink")

Loop

nsqlconnn.Close()

Catch ex As Exception

End Try

End If

End Function
Thanks,
--
----------
'prince
Nov 19 '05 #1
2 1409
Is the path a relative webpath, or a physical path (i.e. c:\whatever)?

I'm sure you checked this already but are you sure the function is returning
a string, and not failing? If an exception is thrown or the datareader is
empty, it will be returning nothing. Also, any reason to type it as an
Object and not a String?

"prince -=nore=-" wrote:
I have a page, where I'm retrieving a file location from a database and
outputting it's contents (HTML) onto a web page.
On the aspx page, I have referred to the code behind it using the line
below. This is where I'm getting the "Object reference not set to an
instance.." error
<% response.writefile(thelink())%>.

The function that line is referring to is below. The record is being
retrieved from the database according to its querystring.

Function thelink() As Object

Dim tow As String

tow = Request.QueryString("tow")

If tow <> "" Then

viewstate("tow") = "@" & tow

CmdIncLink.Parameters.Item("@tow").Value = tow

Dim tow_reader As SqlDataReader

Try

nsqlconnn.Open()

tow_reader = CmdIncLink.ExecuteReader

Do While tow_reader.Read

Return tow_reader("inclink")

Loop

nsqlconnn.Close()

Catch ex As Exception

End Try

End If

End Function
Thanks,
--
----------
'prince

Nov 19 '05 #2
I fixed the problem thanks...

--
----------
'prince
"cmay" <cm**@discussions.microsoft.com> wrote in message
news:67**********************************@microsof t.com...
Is the path a relative webpath, or a physical path (i.e. c:\whatever)?

I'm sure you checked this already but are you sure the function is
returning
a string, and not failing? If an exception is thrown or the datareader is
empty, it will be returning nothing. Also, any reason to type it as an
Object and not a String?

"prince -=nore=-" wrote:
I have a page, where I'm retrieving a file location from a database and
outputting it's contents (HTML) onto a web page.
On the aspx page, I have referred to the code behind it using the line
below. This is where I'm getting the "Object reference not set to an
instance.." error
<% response.writefile(thelink())%>.

The function that line is referring to is below. The record is being
retrieved from the database according to its querystring.

Function thelink() As Object

Dim tow As String

tow = Request.QueryString("tow")

If tow <> "" Then

viewstate("tow") = "@" & tow

CmdIncLink.Parameters.Item("@tow").Value = tow

Dim tow_reader As SqlDataReader

Try

nsqlconnn.Open()

tow_reader = CmdIncLink.ExecuteReader

Do While tow_reader.Read

Return tow_reader("inclink")

Loop

nsqlconnn.Close()

Catch ex As Exception

End Try

End If

End Function
Thanks,
--
----------
'prince

Nov 19 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

4 posts views Thread by My Pet Programmer | last post: by
18 posts views Thread by didacticone | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.