G
Guest
I'm having a problem, and here is a simplified example of code that
demonstrates it:
public class BizObj
{
public string TableName="";
private DataSet oData;
public BizObj()
{
LoadData();
}
public void LoadData()
{
SqlConnection oConn = new SqlConnection("...");
SqlDataAdapter oAdapter = new SqlDataAdapter("SELECT * FROM
"+this.TableName,oConn);
oAdapter.Fill(oData);
}
}
public class AuthorBizObj: BizObj
{
public AuthorBizObj()
{
this.TableName="Authors";
}
}
Now, because the base class constructor fires first, LoadData is called
before the TableName can be set to "Authors".
So I try to override the TableName field in the following manner, hoping
that it will be set before the constructor methods fire:
public class AuthorBizObj: BizObj
{
public string TableName="Authors";
public AuthorBizObj()
{
}
}
But I get a compile warning: "The keyword new is required on
AuthorBizObj.TableName because it hides inherited member BizObj.TableName."
I'm not trying to hide the member, I'm trying to override it.
How can I make sure that the TableName field has the value "Authors" before
the BizObj constructor fires?
<b>This question is strictly about inheritance.</b>
You might say "Pass a value for TableName to the constructor" , but I think
that the Authors bizobj should know its table, not have its name passed into
it.
You might ask "Why do you want to call LoadData in the constructor?" or say
"Call LoadData after you have instantiated AuthorBizObj, not in the
constructor" - I'm actually not creating bizobjs, this is just some sample
code that demonstrates the problem, I'm trying to override a member field,
not figure out where LoadData should be called.
Thanks,
demonstrates it:
public class BizObj
{
public string TableName="";
private DataSet oData;
public BizObj()
{
LoadData();
}
public void LoadData()
{
SqlConnection oConn = new SqlConnection("...");
SqlDataAdapter oAdapter = new SqlDataAdapter("SELECT * FROM
"+this.TableName,oConn);
oAdapter.Fill(oData);
}
}
public class AuthorBizObj: BizObj
{
public AuthorBizObj()
{
this.TableName="Authors";
}
}
Now, because the base class constructor fires first, LoadData is called
before the TableName can be set to "Authors".
So I try to override the TableName field in the following manner, hoping
that it will be set before the constructor methods fire:
public class AuthorBizObj: BizObj
{
public string TableName="Authors";
public AuthorBizObj()
{
}
}
But I get a compile warning: "The keyword new is required on
AuthorBizObj.TableName because it hides inherited member BizObj.TableName."
I'm not trying to hide the member, I'm trying to override it.
How can I make sure that the TableName field has the value "Authors" before
the BizObj constructor fires?
<b>This question is strictly about inheritance.</b>
You might say "Pass a value for TableName to the constructor" , but I think
that the Authors bizobj should know its table, not have its name passed into
it.
You might ask "Why do you want to call LoadData in the constructor?" or say
"Call LoadData after you have instantiated AuthorBizObj, not in the
constructor" - I'm actually not creating bizobjs, this is just some sample
code that demonstrates the problem, I'm trying to override a member field,
not figure out where LoadData should be called.
Thanks,