G
Guest
The console application below demonstrates the problem. Is there a fix?
using System;
using System.Data;
namespace ConAppOverflow
{
class Class1
{
[STAThread]
static void Main(string[] args)
{
// Create a dataset.
DataSet ds = new DataSet("ds");
DataTable dt;
DataRelation dr;
// Create two tables with [very] similar schema
// ID is the key
// CAT is an internal foreign key
// Ref is an external foreign key
// Text is text
dt = new DataTable("DT1");
dt.Columns.Add("ID", System.Type.GetType("System.Int32"));
dt.Columns.Add("CAT", System.Type.GetType("System.Int32"));
dt.Columns.Add("REF", System.Type.GetType("System.Int32"));
dt.Columns.Add("Text", System.Type.GetType("System.String"));
ds.Tables.Add(dt);
//Add relation for internal foreign key
dr = new DataRelation("DT1CAT2ID", dt.Columns["ID"], dt.Columns["CAT"]);
ds.Relations.Add(dr);
// Add some data
dt.Rows.Add(new object[] {1,1,10, ""});
dt.Rows.Add(new object[] {2,1,20, ""});
dt.Rows.Add(new object[] {3,1,30, ""});
dt = new DataTable("DT2");
dt.Columns.Add("ID", System.Type.GetType("System.Int32"));
dt.Columns.Add("CAT", System.Type.GetType("System.Int32"));
dt.Columns.Add("REF", System.Type.GetType("System.Int32"));
dt.Columns.Add("Text", System.Type.GetType("System.String"));
ds.Tables.Add(dt);
//Add relation for internal foreign key
dr = new DataRelation("DT2CAT2ID", dt.Columns["ID"], dt.Columns["CAT"]);
ds.Relations.Add(dr);
// Add some data
dt.Rows.Add(new object[] {10,10,1, ""});
dt.Rows.Add(new object[] {20,10,2, ""});
dt.Rows.Add(new object[] {30,10,3, ""});
// And accept it
ds.Tables["DT1"].AcceptChanges();
ds.Tables["DT2"].AcceptChanges();
// now, edit a row and watch the stack overflow...
DataRow drow = ds.Tables[0].Rows[0];
drow.BeginEdit();
drow["Text"] = "*" + drow["Text"];
drow.EndEdit();
if (ds.HasChanges((DataRowState.Modified)))
{
DataSet xds = ds.GetChanges(DataRowState.Modified);
ds.AcceptChanges();
}
}
}
}
using System;
using System.Data;
namespace ConAppOverflow
{
class Class1
{
[STAThread]
static void Main(string[] args)
{
// Create a dataset.
DataSet ds = new DataSet("ds");
DataTable dt;
DataRelation dr;
// Create two tables with [very] similar schema
// ID is the key
// CAT is an internal foreign key
// Ref is an external foreign key
// Text is text
dt = new DataTable("DT1");
dt.Columns.Add("ID", System.Type.GetType("System.Int32"));
dt.Columns.Add("CAT", System.Type.GetType("System.Int32"));
dt.Columns.Add("REF", System.Type.GetType("System.Int32"));
dt.Columns.Add("Text", System.Type.GetType("System.String"));
ds.Tables.Add(dt);
//Add relation for internal foreign key
dr = new DataRelation("DT1CAT2ID", dt.Columns["ID"], dt.Columns["CAT"]);
ds.Relations.Add(dr);
// Add some data
dt.Rows.Add(new object[] {1,1,10, ""});
dt.Rows.Add(new object[] {2,1,20, ""});
dt.Rows.Add(new object[] {3,1,30, ""});
dt = new DataTable("DT2");
dt.Columns.Add("ID", System.Type.GetType("System.Int32"));
dt.Columns.Add("CAT", System.Type.GetType("System.Int32"));
dt.Columns.Add("REF", System.Type.GetType("System.Int32"));
dt.Columns.Add("Text", System.Type.GetType("System.String"));
ds.Tables.Add(dt);
//Add relation for internal foreign key
dr = new DataRelation("DT2CAT2ID", dt.Columns["ID"], dt.Columns["CAT"]);
ds.Relations.Add(dr);
// Add some data
dt.Rows.Add(new object[] {10,10,1, ""});
dt.Rows.Add(new object[] {20,10,2, ""});
dt.Rows.Add(new object[] {30,10,3, ""});
// And accept it
ds.Tables["DT1"].AcceptChanges();
ds.Tables["DT2"].AcceptChanges();
// now, edit a row and watch the stack overflow...
DataRow drow = ds.Tables[0].Rows[0];
drow.BeginEdit();
drow["Text"] = "*" + drow["Text"];
drow.EndEdit();
if (ds.HasChanges((DataRowState.Modified)))
{
DataSet xds = ds.GetChanges(DataRowState.Modified);
ds.AcceptChanges();
}
}
}
}