How to add Method to Inherited Typed DataSet

J

Joe

Hi

I have a typed dataset and I want to add a method to modify a value in the
datarow.
I want to inherit from the class so if the XSDchanges I would lose my code
when the class regenerates

This is what I am trying with no luck is below. I cannot see JobID in
intellisense after I inherit.
I assume due to it being private

What is the best what to add this method to modify a value in a row?

Thanks

public class JobClass : Schedule

{


public void GenerateNewID()

{

JobID = System.DateTime.Now.Ticks.ToString();





}

}


Genarated Class from XSD
public partial class Schedule : System.Data.DataSet {


private JobsDataTable tableJobs;

[System.CodeDom.Compiler.GeneratedCodeAttribute("System.Data.Design.TypedDataSetGenerator",
"2.0.0.0")]
public partial class JobsRow : System.Data.DataRow {


private JobsDataTable tableJobs;


[System.Diagnostics.DebuggerNonUserCodeAttribute()]

internal JobsRow(System.Data.DataRowBuilder rb) :

base(rb) {

this.tableJobs = ((JobsDataTable)(this.Table));

}


[System.Diagnostics.DebuggerNonUserCodeAttribute()]

public string JobID {

get {

try {

return ((string)(this[this.tableJobs.JobIDColumn]));

}

catch (System.InvalidCastException e) {

throw new System.Data.StrongTypingException("The value for column \'JobID\'
in table \'Jobs\' is DBNull.", e);

}

}

set {

this[this.tableJobs.JobIDColumn] = value;

}

}

}

}
 
D

David Browne

Joe said:
Hi

I have a typed dataset and I want to add a method to modify a value in the
datarow.
I want to inherit from the class so if the XSDchanges I would lose my code
when the class regenerates

This is what I am trying with no luck is below. I cannot see JobID in
intellisense after I inherit.
I assume due to it being private

What is the best what to add this method to modify a value in a row?


First of all, you're going about this the wrong way. DataSets are generated
as partial classes precisely so that you don't have to inherit them to
extend them. Just add your custom code and methods to a different,
non-generated file that contains additional code for the dataset class.
When the DataSet is regenerated, your hand-written extensions are not
overwritten, and are compiled into the DataSet class. That's what partial
classes are for.

Second, I'm not sure what your particular problem is. But trust me, doing
this with partial classes a whole lot easier and more elegant than doing it
with inheritence.

David
 
S

Shawn Wildermuth (C# MVP)

Hello David Browne" davidbaxterbrowne no potted,

David is right, Microsoft doesn't want you to inherit Typed DataSets[1].
In the partial class (which you can have the designer create for you if
you hit F7 when you're in the TDS editor), add a nested class (with the partial
keyword) in your typed dataset and you're set. If you can't figure out how
to make that work, let us know and we'll cruft up a sample.

[1] http://adoguy.com/viewrant.aspx?id=1482

Thanks,
Shawn Wildermuth
Speaker, Author and C# MVP
http://adoguy.com
 

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

Top