Object reference required (question)

B

Bucko

Hi guys,

this may be an easy for someone...

I have a situation like below. The "str" string variable (and any other
variable that VS.net declares normally in this space) can be used fine
in the Page_Load function, but not my own function, "datareaderconvert"

Anyone know why? Here's what it looks like:

namespace mynamespace
{
public class mypage : System.Web.UI.Page
{
protected string str = "";

private void Page_Load(object sender, System.EventArgs e)
{
//useage of str here works fine
}

private DataSet datareaderconvert(SqlDataReader reader)
{
//usage of str doesnt work here
}
}
}
 
A

Alvin Bruney

The web is stateless. If you do not explicitly save the value of str after
page load, when you try to use it after another post it will be gone. You
need to persist the variable somewhere, viewstate, session, cache etc so
that you can pull it out of storage and then use it in your sqlreader
routine
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,016
Latest member
TatianaCha

Latest Threads

Top