Is it not possible to inherit from DataRow?

  • Thread starter Thread starter cmay
  • Start date Start date
C

cmay

I want to add a few methods to the datarow class, but the DataRow
requires a DataRowBuilder in it's constructor, and I can't find a way
to get a DataRowBuilder, and DataRowBuilder has a private constructor.

So is there no way to do this? It kinda stinks.
 
You use the DataTable.NewRow() method to create a DataRow. So, yes, it's
possible to inherit from DataRow to create a new class, but to do it,
basically, you would have to create an inherited DataTable class, and
override the NewRow method, invoking the DataTable.NewRow() method in the
implementation, and casting the return type as your inherited DataRow type.

Another alternative would be to create a class that encapsulates a DataRow
instance.

--
HTH,

Kevin Spencer
Microsoft MVP
Professional Numbskull

This is, by definition, not that.
 
Kevin,

Thanks for the suggestions.

1 question though, is it possible to downcast an object to a derived
class? I thought this was not possible.

If I have a DerivedDataRow, I don't think I can do MyDerivedDataRow=
CType(row, DerivedDataRow).

I think you can only upcast in this case. Is that not correct?

Chris
 
The easiest way to see how this is done is to use Visual Studio to create a
strongly typed DataSet. It creates an XSD file as well as a class file that
contains all of the classes in the DataSet. In Visual Studio you don't
generally work directly with the class file, as the XSD is used to keep the
schema of the classes synchronized with the schema of the underlying
database objects. But the XSD is only used to generate the classes. So, you
can just take a look at how the classes are created by looking at the code.

--
HTH,

Kevin Spencer
Microsoft MVP
Professional Numbskull

Abnormality is anything but average.
 
Back
Top