473,378 Members | 1,542 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,378 software developers and data experts.

DataRow class derivation

Hi,

I wish to use a class derivated from DataRow. The rows within a table are
created with the NewRow method of the DataTable class. So I writed a method
NewSTMTTRNRow() in my class STMTTRNDataTable, but I have an Invalid Cast
Exception in the code "return
((STMTTRNRow)(this.NewRow()));". Where is the bug? What is the smart way to
achieve my goal?

Code :

public class STMTTRNDataTable : DataTable, System.Collections.IEnumerable
{
public STMTTRNRow NewSTMTTRNRow()
{
return ((STMTTRNRow)(this.NewRow()));
}
public System.Collections.IEnumerator GetEnumerator()
{
return this.Rows.GetEnumerator();
}
}

public class STMTTRNRow : System.Data.DataRow
{
private STMTTRNDataTable tableSTMTTRN;
internal STMTTRNRow(DataRowBuilder rb) : base(rb)
{
this.tableSTMTTRN = ((STMTTRNDataTable)(this.Table));
}
}

Ragards,

AFer92

Nov 17 '05 #1
6 6196
André,

The NewRow method is not going to create an instance of the STMTTRNRow
(you might want to reconsider the name there, as it violates naming
guidelines, and is just plain confusing), but rather, it will create an
instance of the DataRow class.

You can't override the NewRow method, so you will have to create an
instance of your row manually, and attach it to the table.

Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"André Fereau" <af****@hotmail.com> wrote in message
news:uA**************@TK2MSFTNGP14.phx.gbl...
Hi,

I wish to use a class derivated from DataRow. The rows within a table are
created with the NewRow method of the DataTable class. So I writed a
method NewSTMTTRNRow() in my class STMTTRNDataTable, but I have an Invalid
Cast Exception in the code "return
((STMTTRNRow)(this.NewRow()));". Where is the bug? What is the smart way
to achieve my goal?

Code :

public class STMTTRNDataTable : DataTable, System.Collections.IEnumerable
{
public STMTTRNRow NewSTMTTRNRow()
{
return ((STMTTRNRow)(this.NewRow()));
}
public System.Collections.IEnumerator GetEnumerator()
{
return this.Rows.GetEnumerator();
}
}

public class STMTTRNRow : System.Data.DataRow
{
private STMTTRNDataTable tableSTMTTRN;
internal STMTTRNRow(DataRowBuilder rb) : base(rb)
{
this.tableSTMTTRN = ((STMTTRNDataTable)(this.Table));
}
}

Ragards,

AFer92

Nov 17 '05 #2
Thanks Nicholas,

How can I create a row manually in a class derived from DataRow? The DataRow
constructor is not available.

André

"Nicholas Paldino [.NET/C# MVP]" <mv*@spam.guard.caspershouse.com> a écrit
dans le message de news: %2****************@tk2msftngp13.phx.gbl...
André,

The NewRow method is not going to create an instance of the STMTTRNRow
(you might want to reconsider the name there, as it violates naming
guidelines, and is just plain confusing), but rather, it will create an
instance of the DataRow class.

You can't override the NewRow method, so you will have to create an
instance of your row manually, and attach it to the table.

Hope this helps.

Nov 17 '05 #3
André,

You created a class that derives from DataRow, right? You can expose
whatever constructor you want. The constructor for DataRow is internal
protected, meaning that if you derive from the class, you can access the
base constructor.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"André Fereau" <af****@hotmail.com> wrote in message
news:eL**************@tk2msftngp13.phx.gbl...
Thanks Nicholas,

How can I create a row manually in a class derived from DataRow? The
DataRow constructor is not available.

André

"Nicholas Paldino [.NET/C# MVP]" <mv*@spam.guard.caspershouse.com> a écrit
dans le message de news: %2****************@tk2msftngp13.phx.gbl...
André,

The NewRow method is not going to create an instance of the STMTTRNRow
(you might want to reconsider the name there, as it violates naming
guidelines, and is just plain confusing), but rather, it will create an
instance of the DataRow class.

You can't override the NewRow method, so you will have to create an
instance of your row manually, and attach it to the table.

Hope this helps.


Nov 17 '05 #4
Nicholas,

I can access the base constructor DataRow(DataRowBuilder rb) but not
DataRow() and I know no mean to create a DataReowBuilder instance.

public class STMTTRNRow : System.Data.DataRow
{
private STMTTRNDataTable tableSTMTTRN;
internal STMTTRNRow() : base() // wrong prototype error!
{
}
internal STMTTRNRow(DataRowBuilder rb) : base(rb) // OK
{
this.tableSTMTTRN = ((STMTTRNDataTable)(this.Table));
}
.............

"Nicholas Paldino [.NET/C# MVP]" <mv*@spam.guard.caspershouse.com> a écrit
dans le message de news: Ou**************@TK2MSFTNGP14.phx.gbl...
André,

You created a class that derives from DataRow, right? You can expose
whatever constructor you want. The constructor for DataRow is internal
protected, meaning that if you derive from the class, you can access the
base constructor.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com


Nov 17 '05 #5
André,

I didn't realize that you couldn't create a DataRowBuilder.

What I would do is create a typed data set, and then look at the
generated code to see how it is creating the typed data rows.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"André Fereau" <af****@hotmail.com> wrote in message
news:Om**************@TK2MSFTNGP12.phx.gbl...
Nicholas,

I can access the base constructor DataRow(DataRowBuilder rb) but not
DataRow() and I know no mean to create a DataReowBuilder instance.

public class STMTTRNRow : System.Data.DataRow
{
private STMTTRNDataTable tableSTMTTRN;
internal STMTTRNRow() : base() // wrong prototype error!
{
}
internal STMTTRNRow(DataRowBuilder rb) : base(rb) // OK
{
this.tableSTMTTRN = ((STMTTRNDataTable)(this.Table));
}
............

"Nicholas Paldino [.NET/C# MVP]" <mv*@spam.guard.caspershouse.com> a écrit
dans le message de news: Ou**************@TK2MSFTNGP14.phx.gbl...
André,

You created a class that derives from DataRow, right? You can expose
whatever constructor you want. The constructor for DataRow is internal
protected, meaning that if you derive from the class, you can access the
base constructor.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

Nov 17 '05 #6
Nicholas,

I've got it! Your idea to build the DataRow manually is the good one.
DataRow is an array of object, it's possible to feed the array. With strong
typed table, we have exception if one object has a wrong type (I want it to
be so).

Regards,

André

public DataRow AddSTMTTRNRow(int BANKACCTFROM, string FITID, System.Byte
TRNTYPE, System.DateTime DTPOSTED, System.DateTime DTUSER, System.DateTime
DTAVAIL, System.Decimal TRNAMT, string CHECKNUM, string SIC, string PAYEEID,
string NAME, string MEMO, System.DateTime DTUPD) {
DataRow rowSTMTTRNRow = this.NewRow();
rowSTMTTRNRow.ItemArray = new object[] {
BANKACCTFROM,
0,
TRNTYPE,
DTPOSTED,
DTUSER,
DTAVAIL,
TRNAMT,
FITID,
CHECKNUM,
"REFNUM",
SIC,
PAYEEID,
NAME,
MEMO
};
this.Rows.Add(rowSTMTTRNRow);
return rowSTMTTRNRow;
}

"Nicholas Paldino [.NET/C# MVP]" <mv*@spam.guard.caspershouse.com> a écrit
dans le message de news: Ol**************@TK2MSFTNGP12.phx.gbl...
André,

I didn't realize that you couldn't create a DataRowBuilder.

What I would do is create a typed data set, and then look at the
generated code to see how it is creating the typed data rows.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com


Nov 17 '05 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Pierre Rouleau | last post by:
Greetings, I'm wondering why the >> operator does not use the write() method of a class derived from the built-in file class as in DerivedFile below. In the following example: - StringFile...
3
by: Teis Draiby | last post by:
I want to write a base class that includes a member function that creates an instance of a derrived class and returns a pointer to it. Problem: The derived class definition has to follow the base...
24
by: Shao Zhang | last post by:
Hi, I am not sure if the virtual keyword for the derived classes are required given that the base class already declares it virtual. class A { public: virtual ~A();
15
by: Steven T. Hatton | last post by:
The following may strike many of you as just plain silly, but it represents the kind of delelima I find myself in when trying to make a design decision. This really is a toy project written for...
19
by: tthunder | last post by:
Hi @all, I've got an interesting problem. These are my classes: ---------------------- class fooBase {
13
by: olanglois | last post by:
Hi, I am trying to derive a new class that will add new functions but no new data members and the base class has overloaded operators (+,-,+=,-=,etc...) returning either (Base &) or (const Base)...
5
by: The Cool Giraffe | last post by:
I'm designing an ABC and in connection to that i have run into some "huh!" and "oh...". Let me put it as a list. 1. Since the class will only contain bodies of the methods, only the header file...
12
by: Shraddha | last post by:
Can I stop people by deriving my class? I mean I don't want my class to be as a base class... Can I do that?
3
by: Ravi | last post by:
Is this the correct way to think of "base class"? The "base class" is a class from which other classes are derived. The "base class" will never be derived from another class.
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.