.NETGURU
Dont understand why this does not work
Messages   Related Types
This message was discovered on microsoft.public.dotnet.framework.aspnet.
Responses highlighted in red are from those people who are likely to be able to contribute good, authoratitive information to this discussion. They include Microsoft employees, MVP's and others who IMHO contribute well to these kinds of discussions.
Post a new message to this list...

Mark Goldin
Very simplified:

namespace humanres

{

public class main2 : System.Web.UI.Page

{

public DataSet Employee

{

get

{

return Employee;

}

set

{

Employee = value;

}

........

Then to access Employee from the user control:

humanres.main2.Employee but it's (Employee) not there.

I am very confused.

Can some please, please explain what am I missing?

Reply to this message...
 
    
Mark Fitzpatrick
You need a place to store the DataSet object. Try the following:

namepace humanres
{
public class main2 : System.Web.UI.Page
{
private DataSet _Employee = null;

public DataSet Employee
{
get
{return _Employee;}
set
{_Employee = value;}
}
}
}

That way the DataSet is getting stored somewhere in the object. Remember, a property is an accessor for a variable that enables setting the variable, and getting the variable. You need a seperate variable somewhere to actually store the object. In the sample code I just added an underscore to the name, but it could be anything as the name is not important, just that the get reuturns an actual variable and the set is able to set some variable.

Hope this helps,
Mark Fitzpatrick
Microsoft MVP- FrontPage

"Mark Goldin" <Click here to reveal e-mail address> wrote in message news:%Click here to reveal e-mail address...
Very simplified:

namespace humanres

{

public class main2 : System.Web.UI.Page

{

public DataSet Employee

{

get

{

return Employee;

}

set

{

Employee = value;

}

.......

Then to access Employee from the user control:

humanres.main2.Employee but it's (Employee) not there.

I am very confused.

Can some please, please explain what am I missing?

Reply to this message...
 
    
Mark Goldin
How am I accessing Employee from the user control?

"Mark Fitzpatrick" <Click here to reveal e-mail address> wrote in message
news:Click here to reveal e-mail address...
You need a place to store the DataSet object. Try the following:

namepace humanres
{
public class main2 : System.Web.UI.Page
{
private DataSet _Employee = null;

public DataSet Employee
{
get
{return _Employee;}
set
{_Employee = value;}
}
}
}

That way the DataSet is getting stored somewhere in the object.
Remember, a property is an accessor for a variable that enables setting the
variable, and getting the variable. You need a seperate variable somewhere
to actually store the object. In the sample code I just added an underscore
to the name, but it could be anything as the name is not important, just
that the get reuturns an actual variable and the set is able to set some
variable.

Hope this helps,
Mark Fitzpatrick
Microsoft MVP- FrontPage

"Mark Goldin" <Click here to reveal e-mail address> wrote in message
news:%Click here to reveal e-mail address...
Very simplified:

namespace humanres

{

public class main2 : System.Web.UI.Page

{

public DataSet Employee

{

get

{

return Employee;

}

set

{

Employee = value;

}

.......

Then to access Employee from the user control:

humanres.main2.Employee but it's (Employee) not there.

I am very confused.

Can some please, please explain what am I missing?

Reply to this message...
 
    
Greg Burns
In your usercontrol use this line:

DataSet ds = ((humanres.main2)Page).Employee;

Greg

"Mark Goldin" <Click here to reveal e-mail address> wrote in message
news:Click here to reveal e-mail address...
[Original message clipped]

Reply to this message...
 
    
Mark Goldin
I tried that.
Here is an error:

Server Error in '/humanres' Application.

----------------------------------------------------------------------------
----

Value cannot be null. Parameter name: dataSet
Description: An unhandled exception occurred during the execution of the
current web request. Please review the stack trace for more information
about the error and where it originated in the code.

Exception Details: System.ArgumentNullException: Value cannot be null.
Parameter name: dataSet

Source Error:

Line 56:             SqlConnection conn = new SqlConnection("Initial
Catalog=manpower;Data Source=devsrv00;uid=SoSTransWebUser;pwd=yurymark;");
Line 57:             SqlHelper.FillDataset(conn, CommandType.Text, "select * from
udf_getEmployeeDetails(" + EmployeeId + ")",
Line 58:             ds, new string[]{"employee"});

"Greg Burns" <Click here to reveal e-mail address> wrote in message
news:#Click here to reveal e-mail address...
[Original message clipped]

Reply to this message...
 
    
Greg Burns
(Using Mark's example) Have you populated your private _Employee variable in
your main2 webform prior to trying to access it in the usercontrol using
main2's public Employee property?

Greg

"Mark Goldin" <Click here to reveal e-mail address> wrote in message
news:%Click here to reveal e-mail address...
[Original message clipped]

Reply to this message...
 
    
Mark Goldin
No, I did not populate it.
I am trying to fill Employee with data in a user control and it fails.

"Greg Burns" <Click here to reveal e-mail address> wrote in message
news:Click here to reveal e-mail address...
> (Using Mark's example) Have you populated your private _Employee variable
in
[Original message clipped]

Reply to this message...
 
    
Greg Burns
Well all the code that has been provided assumed that main2 filled the
dataset and you were trying to read it in the usercontrol.

I am terribly confused.

Are you trying to read the usercontrol's dataset from the webform? The
reverse of what I (we) thought.

Greg

"Mark Goldin" <Click here to reveal e-mail address> wrote in message
news:Click here to reveal e-mail address...
[Original message clipped]

Reply to this message...
 
    
Mark Goldin
What I am trying to do is this:
I want to have a dataset that will be accessable from any part of the
project.
Some user contols will read it to populate other controls with data.
Some controls will save dataset to the server.

"Greg Burns" <Click here to reveal e-mail address> wrote in message
news:Click here to reveal e-mail address...
[Original message clipped]

Reply to this message...
 
    
Greg Burns
When you say project do your mean a single webform, or multiple webforms?
If multiple, then you need to store it in cache or session so that you read
it from other pages. OR fill you dataset on every page_load on every
webform that you need it.

If you want the dataset to be accessible from multiple forms and
usercontrols on those forms, then simply use cache. If the dataset is
specific to a single user, then use session.

If you are loading it on EVERY page_load, then it makes sense (to me at
least) to not use cache or sesssion, and use the technique Karl showed to
make the ds on the webform accessible to all it's child usercontrols.

Maybe post some code.

Greg

"Mark Goldin" <Click here to reveal e-mail address> wrote in message
news:Click here to reveal e-mail address...
[Original message clipped]

Reply to this message...
 
    
Mark (VIP)
My project has one webform and a number of user and custom controls.
I need to be able to access that dataset from any code that is a part of the
project.
So main form will have a component to populate that dataset with data,
another control to read from it, and another component to save to the
database.
So my thinking was to create a global property (dataset) to access it from
anywhere.
Am I having it all wrong?

"Greg Burns" wrote:

[Original message clipped]

Reply to this message...
 
    
Greg Burns
These "components" sounds more like a Data Access Layer class than a
usercontrol.

Greg

"Mark" <Click here to reveal e-mail address> wrote in message
news:Click here to reveal e-mail address...
[Original message clipped]

Reply to this message...
 
    
Karl
Well, your example is a little too simple but...
Employee is a property of your main2 class located in the humanres namespace. Employee is an instance property, as opposed to a static propery. I wouldn't even think humanres.main2.Employee would compile.

From your user control, you could do

DataSet ds = ((humanres.main2)Page).Employee;

Page is the actual instance of your main2 class.

Do do it your way, you'd do

public static DatSet Employee{
get { return Employee; }
set { Employee = value; }
}

but I'm about 95% sure that isn't what you want and will not behave as you expect.

Also, I imagine it's just a typo, but your property "Employee"'s get accessor returns itself, which will have viscious side-effects....

Karl

--
MY ASP.Net tutorials
http://www.openmymind.net/

"Mark Goldin" <Click here to reveal e-mail address> wrote in message news:%Click here to reveal e-mail address...
Very simplified:

namespace humanres

{

public class main2 : System.Web.UI.Page

{

public DataSet Employee

{

get

{

return Employee;

}

set

{

Employee = value;

}

.......

Then to access Employee from the user control:

humanres.main2.Employee but it's (Employee) not there.

I am very confused.

Can some please, please explain what am I missing?

Reply to this message...
 
 
System.ArgumentNullException
System.Data.CommandType
System.Data.DataSet
System.Data.SqlClient.SqlConnection
System.Web.UI.Page




ExamGuru IT Solutions - .Net Guru is owned and operated by ExamGuru, Inc., the man behind .Net Guru. If you're in the market for bespoke software or software consultancy, why not get him and his highly trained team to help? - www.examguru.net/ITCertification
Ad


Need Dot Net Interview Questions?
Ask ExamGuru, Inc. for advice and help on Passing .Net Interviews
.Net Projects
Best-of-breed application framework for .NET projects, developed by ExamGuru, Inc. and ExamGuru IT
Free .net Help
Commission ExamGuru, Inc. and his team for your next bespoke software project
FogBUGZ
The only bug tracking system carefully crafted with one goal in mind: helping teams create great software.
Awesome Tools
If you don't know about these, you're missing out... IT Certification Questions
IT Interview Questions
Free Oracle 10g Training
MCSE Boortcamp
Cisco Study Guides
Cheap Study Guides
Exact Questions
Dot Net Interview Questions
Oracle OCP
Cheap Travel
Designer Perfumes - Wholesale Prices
Free Programming Tutorials
 
ExamGuru IT Solutions - .Net Guru is owned and operated by ExamGuru, Inc., the man behind .Net Guru. If you're in the market for bespoke software or software consultancy, why not get him and his highly trained team to help? - www.examguru.net/ITCertification
 Copyright © ExamGuru, Inc. 2001-2006
Contact Us - Terms of Use - Privacy Policy - www.dot-net-guru.com - www.examguru.net - www.oraclesource.net - www.itinterviews.net - www.examguru.net/ITCertification