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);
}
}
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);
}
}