Groups | Blog | Home
all groups > dotnet windows forms databinding > june 2006 >

dotnet windows forms databinding : BindingSource strange dehaviour



Neil
6/13/2006 6:03:31 AM
Can anyone tell me why the following snippet of code throws an
exception on the forth iteration of the loop? If we comment out the
last line of code everything is okay.


DataSet dataSet = new DataSet();
DataTable dataTable = dataSet.Tables.Add();
DataColumn dataColumn = dataTable.Columns.Add();
dataColumn.ColumnName = "PrimaryKey";
dataColumn.AutoIncrement = true;
dataTable.PrimaryKey = new DataColumn[] { dataColumn };

BindingSource bindingSource = new BindingSource();
bindingSource.DataSource = new DataView(dataTable);


for (int i = 0; i < 10; i++)
{
dataSet.Clear();
dataTable.Rows.Add();
bindingSource.Find("PrimaryKey", 33);
}
Neil
6/14/2006 3:10:25 AM
Some more information:

Here is the stack trace of the exception

Unhandled Exception: System.NullReferenceException: Object reference
not set to an instance of an object.
at System.Data.DataColumn.IsNotAllowDBNullViolated()
at System.Data.DataSet.EnableConstraints()
at System.Data.DataSet.set_EnforceConstraints(Boolean value)
at System.Data.DataSet.Clear()


Also if we change the line

bindingSource.DataSource = new DataView(dataTable);

to

bindingSource.DataSource = dataTable;

then no exception id thrown.
AddThis Social Bookmark Button