Click here to Skip to main content
15,886,689 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi all,

I'm developing a Order Manage System. I designed the entities as strong typed dataset, in other words, a object in then system a business object (e.g. Order, Trade or Payment) is a datarow(a strong typed datarow).
For example, a Order class(inherit DataRow) have a property - BuyerInfo(inherit DataRow). When I init a Order object and it's property BuyerInfo successfully, and get then property values of the BuyerInfo object, a RowNotInTableException threw. show the following message.
"This row has been removed from a table and does not have any data. BeginEdit() will allow creation of new data in this row."
Anyone know why? Datarow could NOT be a property datatype of a class? thanks.

these another tips here, when I change then member of then Order what saved then BuyerInfo object to a Datatable from Datarow, then exception disappeared! see following code:

Begfore Changing.
C#
#region BuyerInfo of Trade
private BuyerInfoRow m_drBuyerInfo;
/// <summary>
/// BuyerInfo of Trade
/// </summary>
public BuyerInfoRow BuyerInfo
{
    get
    {
        return this.m_drBuyerInfo;
    }
    set
    {
        if (value != null)
        {
            this.m_drBuyerInfo = value;
            this.buyer_info_id = value.tbbi_gID;
        }
    }
}
#endregion

After Changing:
C#
#region BuyerInfo of Trade
// these is only one datarow in then datatable, what saved then Buyer Information of this Trade
private BuyerInfo_tbbiDataTable m_dtBuyerInfo;
/// <summary>
/// BuyerInfo of Trade
/// </summary>
public BuyerInfoRow BuyerInfo
{
    get
        {
            if ((this.m_dtBuyerInfo == null) || (this.m_dtBuyerInfo.Rows == null) || (this.m_dtBuyerInfo.Count <= 0))
            {
                return null;
                       
            }
            else
            {
                return this.m_dtBuyerInfo[0];
            }
        }
    set
        {
            if (value != null)
            {
                if ((this.m_dtBuyerInfo != null) && (this.m_dtBuyerInfo.Rows != null) && (this.m_dtBuyerInfo.Count > 0))
                {
                    this.m_dtBuyerInfo.Clear();
                }

                if (this.m_dtBuyerInfo == null)
                {
                    this.m_dtBuyerInfo = new BuyerInfo_tbbiDataTable();
                }

                this.m_dtBuyerInfo.ImportRow(value);
                this.buyer_info_id = value.tbbi_gID;
            }
        }
}
#endregion
Posted
Updated 13-Jan-15 7:49am
v2
Comments
Tomas Takac 13-Jan-15 14:01pm    
DataRow must always be part of a DataTable. How do you create it, in the former example?
KentBill 13-Jan-15 22:47pm    
Thank you, Tomas, I created the strong typed DataRow class - BuyerInfoRow in following way.
I created the entity classes of the system as strong typed DataSet. In Visual Studio .NET, I created a Datset.cs file in project, and drop a table(e.g. Order table) from Server Explorer, it creates the classes of Order(OrderDatatable, OrderRow, OrderColumn, OrderTableAdapter....), include OrderDataTable, OrderRow, OrderColumn.... Create the classes of BuyerInfo by same way, and extend then OrderRow class, added a property BuyerInfo it's datatype is BuyerInfoRow, please see the following code.


public partial class DataSet1 {

///
/// Extend the OrderRow class
///
partial class OrderRow
{

#region BuyerInfo of Order

private BuyerInfoRow m_drBuyerInfo;

///
/// BuyerInfo of Order
///
public BuyerInfoRow BuyerInfo
{
get
{
return this.m_drBuyerInfo;
}
set
{
if (value != null)
{
this.m_drBuyerInfo = value;
}
}
}
#endregion
}
Tomas Takac 14-Jan-15 3:42am    
What I meant is how do you create the instance of BuyerInfoRow. I presume you create it outside of the class and then assign it to the BuyerInfo property. There must be a table into which you load the data in the first place. So my guess is you the remove the row from the original table which causes the error.
KentBill 14-Jan-15 23:26pm    
Yes, you are right, the BuyerInfo property of Order object will be init when Order object created, I query the buyer information row in the table by buyer ID from order object, and assign it to the BuyerInfo property.
Tomas Takac 14-Jan-15 3:49am    
Another idea. I think you should not store the parent row (buyerinfo) in the child row (order) directly but rather use data relations[^] to retrieve it on the fly. I remember doing this long time ago.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900