PC Review
Forums
Newsgroups
Microsoft DotNet
Microsoft ADO .NET
BindingSource.Find causing problems
Forums
Newsgroups
Microsoft DotNet
Microsoft ADO .NET
BindingSource.Find causing problems
![]() |
BindingSource.Find causing problems |
|
|
Thread Tools | Rate Thread |
|
|
#1 |
|
Guest
Posts: n/a
|
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. |
|
![]() |
|
| Thread Tools | |
| Rate This Thread | |
|
|

Main Page 

