PC Review


Reply
Thread Tools Rate Thread

BindingSource.Clear method

 
 
Isaac Abraham
Guest
Posts: n/a
 
      26th Nov 2005
Hiya,

I'm mucking around with .net 2, and experimenting with the BindingSource
control. I've set the datasource to a dataset and set the datamember
property as the table (or perhaps i've directly set the datasource to
the table and left the datamember as null). When I run the Clear()
method on the BindingSource, I get an exception from the runtime saying
that the clear method cannot be used on the underlying datasource.

Any ideas what I'm doign wrong?

Thanks
 
Reply With Quote
 
 
 
 
Bart Mermuys
Guest
Posts: n/a
 
      26th Nov 2005
Hi,

"Isaac Abraham" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> Hiya,
>
> I'm mucking around with .net 2, and experimenting with the BindingSource
> control. I've set the datasource to a dataset and set the datamember
> property as the table (or perhaps i've directly set the datasource to the
> table and left the datamember as null). When I run the Clear() method on
> the BindingSource, I get an exception from the runtime saying that the
> clear method cannot be used on the underlying datasource.
>
> Any ideas what I'm doign wrong?


I don't think you're doing anything wrong, it just can't be done. You have
to Clear the underlying DataTable instead.

HTH,
Greetings


>
> Thanks



 
Reply With Quote
 
Paul Gielens
Guest
Posts: n/a
 
      26th Nov 2005

See this
(http://msdn2.microsoft.com/library/s...rce.clear.aspx)
example where the table is assigned to the BindingSource.DataSource
property. Internally the table its DataRow collection is bound to the
connector. The Clear operation now deletes all data rows from your table.



###
Best regards,
Paul Gielens

Visit my blog @ http://weblogs.asp.net/pgielens/





"Isaac Abraham" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> Hiya,
>
> I'm mucking around with .net 2, and experimenting with the BindingSource
> control. I've set the datasource to a dataset and set the datamember
> property as the table (or perhaps i've directly set the datasource to the
> table and left the datamember as null). When I run the Clear() method on
> the BindingSource, I get an exception from the runtime saying that the
> clear method cannot be used on the underlying datasource.
>
> Any ideas what I'm doign wrong?
>
> Thanks
>




 
Reply With Quote
 
Bart Mermuys
Guest
Posts: n/a
 
      26th Nov 2005
Hi,

"Paul Gielens" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
>
> See this
> (http://msdn2.microsoft.com/library/s...rce.clear.aspx)
> example where the table is assigned to the BindingSource.DataSource
> property. Internally the table its DataRow collection is bound to the
> connector. The Clear operation now deletes all data rows from your table.


I don't see an example. And when you bind a DataTable then it's internally
bound to the DefaultView (DataView).

A DataTable isn't directly bindable because it doesn't implement IList, it
does implement IListSource which provides the DefaultView.

DataTable dt = new DataTable();
dt.Columns.Add( "test", typeof(string) );
BindingSource bs = new BindingSource(dt, "");
Console.WriteLine( bs.List.GetType() ); // prints DataView
Console.WriteLine( bs.List == dt.DefaultView ); // prints true


Greetings

>
>
>
> ###
> Best regards,
> Paul Gielens
>
> Visit my blog @ http://weblogs.asp.net/pgielens/
>
>
>
>
>
> "Isaac Abraham" <(E-Mail Removed)> wrote in message
> news:(E-Mail Removed)...
>> Hiya,
>>
>> I'm mucking around with .net 2, and experimenting with the BindingSource
>> control. I've set the datasource to a dataset and set the datamember
>> property as the table (or perhaps i've directly set the datasource to the
>> table and left the datamember as null). When I run the Clear() method on
>> the BindingSource, I get an exception from the runtime saying that the
>> clear method cannot be used on the underlying datasource.
>>
>> Any ideas what I'm doign wrong?
>>
>> Thanks
>>

>
>
>



 
Reply With Quote
 
Paul Gielens
Guest
Posts: n/a
 
      26th Nov 2005

This showed up while inspecting the DataView class with reflector:
void IList.Clear()
{
throw ExceptionBuilder.CanNotClear();
}public static Exception CanNotClear()
{
return
ExceptionBuilder._Argument(Res.GetString("DataView_CanNotClear"));
}

I was assuming that the ListDictionaryInternal collection class which is
being used inside the DataView class was capable of clearing its values, and
so it seems with reflector. What I overlooked is the DataView class relying
on the IBindingListView (inheriting IBindingList and IList) contract and
thus implements the Clear operation.

Sorry for the wrong link... this would be the correct one
http://msdn2.microsoft.com/library/s...urce.list.aspx.
Hope this clears things up.

###
Best regards,
Paul Gielens

Visit my blog @ http://weblogs.asp.net/pgielens/


"Bart Mermuys" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
>
> Hi,
>
> "Paul Gielens" <(E-Mail Removed)> wrote in message
> news:(E-Mail Removed)...
>>
>> See this
>> (http://msdn2.microsoft.com/library/s...rce.clear.aspx)
>> example where the table is assigned to the BindingSource.DataSource
>> property. Internally the table its DataRow collection is bound to the
>> connector. The Clear operation now deletes all data rows from your table.

>
> I don't see an example. And when you bind a DataTable then it's
> internally bound to the DefaultView (DataView).
>
> A DataTable isn't directly bindable because it doesn't implement IList, it
> does implement IListSource which provides the DefaultView.
>
> DataTable dt = new DataTable();
> dt.Columns.Add( "test", typeof(string) );
> BindingSource bs = new BindingSource(dt, "");
> Console.WriteLine( bs.List.GetType() ); // prints DataView
> Console.WriteLine( bs.List == dt.DefaultView ); // prints true
>
>
> Greetings
>



 
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

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
BindingSource.AddNew Method Thammarat charoenchai. Microsoft VB .NET 2 12th May 2007 05:26 AM
BindingSource AddingNew method with DataSets Flomo Togba Kwele Microsoft ADO .NET 3 17th Feb 2007 06:24 AM
bindingsource.find method not working Mohan Microsoft Dot NET Framework Forms 1 28th Aug 2006 03:22 PM
bindingsource.find method not working Mohan Microsoft Dot NET Compact Framework 1 25th Aug 2006 10:03 PM
Bindingsource Find method Mark Huisinga Microsoft Dot NET Compact Framework 11 23rd Jun 2006 09:17 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 06:57 AM.