PC Review Forums Newsgroups Microsoft DotNet Microsoft ADO .NET BindingSource.Find causing problems

Reply

BindingSource.Find causing problems

 
Thread Tools Rate Thread
Old 17-06-2006, 10:32 AM   #1
neil@walters.org.uk
Guest
 
Posts: n/a
Default BindingSource.Find causing problems


Hi all

I have an ADO problem when I call BindingSource.Find and the
BindingSource.DataSource is set to a DataView. Here is some sample code
to illustrate my problem

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

This sample code produces the folowing 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()

However, if we comment out the line

bindingSource.Find("PrimaryKey", 33);

The exception is not thrown.

Similarly, no exception is thrown if we change the line

bindingSource.DataSource = new DataView(dataTable);

to

bindingSource.DataSource = new dataTable;



Does anyone have any ideas as to why this is happening?

Thanks
Neil.

  Reply With Quote
Reply



Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off