Exception: There is no Proposed data to access. (???)

A

anonymous

I used ADO.Net to create two tables - parent and child
tables. And, added a relation between two tables. Then, I
setup a column of child table to lookup value from
parent table. So far so good.

But, when I modified a context of child table, I got a
Exception - "There is no Proposed data to access."!.

Can anyone explan what go wrong and a solution?

Attached is a sample:
-----------------------------------------------------------
static void Main(string[] args)
{
// Create a dataset
DataSet ds = new DataSet();

// Create a parent table, and add into the dataset
DataTable parentDT = new DataTable();
parentDT.Columns.Add("ID", System.Type.GetType
("System.Int32"));

parentDT.Columns.Add("Name", System.Type.GetType
("System.String"));

DataRow newRow = parentDT.NewRow();
newRow["ID"] = 0;
newRow["Name"] = "John";
parentDT.Rows.Add(newRow);

ds.Tables.Add(parentDT);

// Create a child table, adn add into the dataset
DataTable childDT = new DataTable();
childDT.Columns.Add("ID", System.Type.GetType
("System.Int32"));
childDT.Columns.Add("Name", System.Type.GetType
("System.String"));
childDT.Columns.Add("Description", System.Type.GetType
("System.String"));

newRow = childDT.NewRow();
newRow["ID"] = 0;
newRow["Description"] = "Administrator";
childDT.Rows.Add(newRow);

s.Tables.Add(childDT);

// Create a relation
ds.Relations.Add("relation", parentDT.Columns["ID"],
childDT.Columns["ID"], false);

// Setup the expresion for the column "Name" of child
table
childDT.Columns["Name"].Expression = "Parent
(relation).Name";

// Now, modify the column "Description" of child table
try
{
DataRow row = childDT.Rows[0];
row["Description"] = "Engineer";

Console.WriteLine("ID:\t" + row["ID"].ToString());
Console.WriteLine("Name:\t" + row["Name"].ToString());
Console.WriteLine("Description:\t" + row
["Description"].ToString());
}
catch(Exception e)
{
Console.WriteLine("Exception:\t" + e.Message);
}
}
 
A

anonymous

Thanks stan and jerry to response my original question.

As stan point out, it is a bug from MS. The real problem
is that if you use DataColumn.Expression, you will get the
exception when you update the child table.

The solution jerry gave is to avoid using Expression.

I found another workaround if you really want to use
Expression. I found that you can still add/delete rows
from the child table. Therefore, when you update a row,
you can create a new row and make necessary changes before
adding it into the child table, then delete the original
row and add the new row into the table.

This solution is a little bit noise. It will fire
RowChanging/RowChanged/RowDeleting/RowDeleted events. That
will probably trigger other events such as refresh user
interface. Also, be aware to that solution will not fire
ColumnChanging/ColumnChanged events.
 
J

jerry

No, no, no. The article to which I referred you did not instruct you on
how to avoid expressions. On the contrary, it detailed how to create a
custom column which would display the result of any expression, including
a lookup into another table, without causing the "no proposed value" error
when you edit other columns.

anonymous wrote...
 
A

anonymous

Jerry,

The idea behind the article is to use Relationship by your
self to do the work that Expression supposed to do. You
got it!
 
S

Stan Sainte-Rose

FYI
I found a hint on the tawain MS community..

1. Don't edit the row.
2. Manually call BeginEdit on the parent row before editing the child row.

You can call CancelEdit afterwards since we're not really editing, just
making sure the correct row version exisits.



It seems it works fine...



Stan
 

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