Click here to Skip to main content
15,901,122 members

Comments by KentBill (Top 5 by date)

KentBill 18-Jan-15 19:54pm View    
I think I found why then exception was thrown. The DataRow object BuyerInfoRow being a property of another class. It was inited in a method(named MethodA) with a DataTable method - NewRow(), and the DataTable object is a local variable of the MethodA, and then the BuyerInfoRow object access by another method(named MehtodB). When MethodA finished running, the DataTable object which the DataRow object belong to was over its life circle and released, in another word, DataRow object lost its DataTable property value and RowState property changed to Detached, after that, in MethodB, while DataRow object was accessed, RowNotInTableException Throw.
KentBill 15-Jan-15 20:45pm View    
And then in the set operation of property BuyerInfo, I query the row(s) by relation and update them?
KentBill 14-Jan-15 23:30pm View    
You mean I should design the "Master - Detail" relationship of the entities to be data relations, instead of class and it’s properties?
KentBill 14-Jan-15 23:26pm View    
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.
KentBill 13-Jan-15 22:47pm View    
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
}