c#.net calling method's

gRoberts12

Newcomer
Joined
Aug 5, 2005
Messages
7
Hey peeps,

I've got a situation where I need some help if possible.

I've got my class setup, and i've told it to create a method:

Code:
		private void UserDetails()
		{
			if(Session["User"] != null)
			{
				SqlConnection UserDetails_Connection = new SqlConnection("server=xx.xxx.xxx.xx;uid=xxxxxx;pwd=xxxxx;database=xxxxxx");
				SqlCommand UserDetails_Command = new SqlCommand("SELECT * FROM Users WHERE Username like '" + Session["User"] + "'",UserDetails_Connection);
				try
				{
					UserDetails_Connection.Open();
					UserDetails_Read = UserDetails_Command.ExecuteReader();
					UserDetails_Read.Read();
					
					UserDetail.Add(UserDetails_Read.GetInt32(0));
					UserDetail.Add(UserDetails_Read.GetValue(1));
				}
				catch(Exception Ex)
				{
					Response.Write(Ex.Message);
				}
				finally
				{
					UserDetails_Read.Close();
					UserDetails_Connection.Close();
				}
			}
		UserDetails_Arr = UserDetail.ToArray();
		}

Now when the user log's in, I want to be able to store their user details into an array of which I can access through-out my pages.

But for some weird reason, my main aspx page see's the class, and will act upon onLoad methods etc, but when I call UserDetails() it says it can't find it, even if I do this:

EYCDWEB.Generic Bob = new EYCDWEB.Generic();
Bob.UserDetails();

can anyone shed some light on why my methods are not public, i'm getting the following error when I try:

'what i'm trying to call' does not exist in the current context

Cheers

Gav
 
i've tried changing it to public, and all I get is the above error, so I tried calling it by the namespace and class of the class file, ie EYCDWEB.Generic.UserDetails(); but that just came back with UserDetails cannot be found, i've recompiled my code using csc, and it doesn't error?

Anything else?

Gav
 
I dont think its about the method itself. Its probably the Session object you're trying to have access within your method. I've seen this error many time in the OnInit context. Session is one of the objects you cannot have access in this context. You have to wait to the OnLoad event. But first make you method public or it will never work. Make it public, an then check if your method is called within the OnInit context. If so, you'll have to take away the Session object.
 
I created the UserDetails() method so I don't cramp up my onLoad event, instead I just stuck UserDetails() in the onLoad event. It's weird because if I create an win32 app then I can access anything that is called within the codebehind class. Although there is an linking namespace between the two files when creating them in VS.net 2003.

I'm hand coding everything my self as VS.net 2003 gives you loads of files that you just don't need, where as if I hand code it, and compile it using csc, I only build the files I need to deploy rather then having to constantly fish for files.

I've also gone back to using my original way of coding rather then using an codebehind, i've just stuck all my needing coding into an file, and then called it with querystrings. Which works for now, but I need to retrieve data without sticking all the code inline with my aspx.

I work with someone who knows alot of c#.net so I will ask him when I return to work today.

Thanks

Gav
 
Back
Top