.NETGURU
why is "this" read-only?
Messages   Related Types
This message was discovered on ASPFriends.com 'aspngcs' list.
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.

Edward Tanguay
-- Moved from [aspfreeforall] to [aspngcs] by Marcie Jones <Click here to reveal e-mail address> --

Why do I get the error "cannot assign to '<this>' because it is read-only?

How can I make it non-read-only or what is the problem here:

class DataMenu : DataTable {
public DataMenu() {
DataSet ds = new DataSet();
SqlDataAdapter da = new SqlDataAdapter();
SqlConnection con = new
SqlConnection(ConfigurationSettings.AppSettings["con"]);
string theSql = "SELECT * FROM finPages ORDER BY PageSort";
SqlCommand cmd = new SqlCommand(theSql, con);
da.SelectCommand = cmd;
da.Fill(ds);
this = ds.Tables[0];
}
}

Thanks,
Edward Tanguay
www.tanguay.info

_________________________________________________________________
Join the world’s largest e-mail service with MSN Hotmail.
http://www.hotmail.com

Reply to this message...
 
    
Steve Sharrock (VIP)
I think you're going to have even further problems using DataMenu as a
subclass of DataTable. You won't be able to assign a DataTable to an
object of type DataMenu even if you do it from outside the class to
avoid the "this" reference. You will be unable to cast the DataTable to
a DataMenu (although you can go the other way because of the
inheritance).

Consider favoring composition over inheritance--that is, consider have
DataMenu contain an object of type DataTable.

2-cents on a Saturday afternoon.

Steve Sharrock
programmer / designer
www.sharkcode.com

-----Original Message-----
From: Edward Tanguay [mailto:Click here to reveal e-mail address]
Sent: Saturday, July 06, 2002 11:23 AM
To: aspngcs
Subject: [aspngcs] why is "this" read-only?

-- Moved from [aspfreeforall] to [aspngcs] by Marcie Jones
<Click here to reveal e-mail address> --

Why do I get the error "cannot assign to '<this>' because it is
read-only?

How can I make it non-read-only or what is the problem here:

class DataMenu : DataTable {
public DataMenu() {
DataSet ds = new DataSet();
SqlDataAdapter da = new SqlDataAdapter();
SqlConnection con = new
SqlConnection(ConfigurationSettings.AppSettings["con"]);
string theSql = "SELECT * FROM finPages ORDER BY PageSort";
SqlCommand cmd = new SqlCommand(theSql, con);
da.SelectCommand = cmd;
da.Fill(ds);
this = ds.Tables[0];
}
}

Thanks,
Edward Tanguay
www.tanguay.info

_________________________________________________________________
Join the world's largest e-mail service with MSN Hotmail.
http://www.hotmail.com

| [aspngcs] member Click here to reveal e-mail address = YOUR ID
| http://www.asplists.com/asplists/aspngcs.asp = JOIN/QUIT

Reply to this message...
 
    
Herbert Wildmeister
I'm not using a DataTable or anything ..., but I'm also looking for an efficient workaround for CS1604
I'm trying to achieve something like [Code]this = new MyClass();[/Code]
i.e. I want to redirect all refferences to this to a different object of the same type. I've read that C# stores a list of all references to an object (for garbage collection). Can I access this list? Can I redirect all references in this list? How? Or is there a different solution to my problem.
Thanks a lot.
Reply to this message...
 
 
System.Configuration.ConfigurationSettings
System.Data.DataSet
System.Data.DataTable
System.Data.SqlClient.SqlCommand
System.Data.SqlClient.SqlConnection
System.Data.SqlClient.SqlDataAdapter




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