PC Review


Reply
Thread Tools Rate Thread

Add New in Bindings Navigator problem

 
 
Vayse
Guest
Posts: n/a
 
      10th Nov 2005
Vb.net 2005, Developer Edition.
When one creates a bindings navigator, one of the standard buttons created
on the toolbar is Add New. Which works fine if you create a new item.
However, if you don't enter any data, and click previous record or Move
First, an error is generated. (there are previous records) In my case, in
frmProducts I get "ProductCode cannot be null"
Two questions

1) How do I trap for this error. Since theres no code in frmProducts.vb for
the Previous Record button, I'm unsure of how to trap it.

2) How do I solve this issue?

Thanks
Vayse


 
Reply With Quote
 
 
 
 
Kevin Yu [MSFT]
Guest
Posts: n/a
 
      11th Nov 2005
Hi Vayse,

You're getting the error, because the typed dataset doesn't allow null in
the ProductCode column, and you didn't input anything into this field, so
the exception is thrown.

I assume that you're using a DataGridView to list all the data in the
dataset. So in this case, the exception is thrown by the DataGridView
instead of the BindingNavigator. If so, you can handle the
DataGridView.DataError event to trap this. Here are the steps:

1. Click the DataGridView on the designer.
2. In the properties window, switch to event view.
3. Double click on DataError and it will create the event handler for you.
4. Add code in the event handler.

Kevin Yu
=======
"This posting is provided "AS IS" with no warranties, and confers no
rights."

 
Reply With Quote
 
Vayse
Guest
Posts: n/a
 
      11th Nov 2005
Hi Kevin
I'm not using the Datagridview, just a normal form. I don't see a DataError
event in the form events, or in the ProductsBindingNavigator.
What should I do in this case?
Thanks
Vayse


"Kevin Yu [MSFT]" <v-(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> Hi Vayse,
>
> You're getting the error, because the typed dataset doesn't allow null in
> the ProductCode column, and you didn't input anything into this field, so
> the exception is thrown.
>
> I assume that you're using a DataGridView to list all the data in the
> dataset. So in this case, the exception is thrown by the DataGridView
> instead of the BindingNavigator. If so, you can handle the
> DataGridView.DataError event to trap this. Here are the steps:
>
> 1. Click the DataGridView on the designer.
> 2. In the properties window, switch to event view.
> 3. Double click on DataError and it will create the event handler for you.
> 4. Add code in the event handler.
>
> Kevin Yu
> =======
> "This posting is provided "AS IS" with no warranties, and confers no
> rights."
>



 
Reply With Quote
 
Kevin Yu [MSFT]
Guest
Posts: n/a
 
      12th Nov 2005
Hi Vayse,

Do you mean that you have only a BindingNavigator on the form without
showing the data? In this case the only thing we can do is to set the
DataSet's EnforceConstraint property to true. However, this is not
recommended.

Since the ProductCode field doesn't allow null value, it's better for us to
add a control to input data for it.

Kevin Yu
=======
"This posting is provided "AS IS" with no warranties, and confers no
rights."

 
Reply With Quote
 
Vayse
Guest
Posts: n/a
 
      14th Nov 2005
To make things clearer, I've set up a simple example.
I have a screenshot here
http://h1.ripway.com/vayse/SampleProducts.bmp

In fact, I've even put a zip file here
http://h1.ripway.com/vayse/SampleProducts.zip

So, what should I do to stop the error occuring?
Thanks
Vayse



"Kevin Yu [MSFT]" <v-(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> Hi Vayse,
>
> Do you mean that you have only a BindingNavigator on the form without
> showing the data? In this case the only thing we can do is to set the
> DataSet's EnforceConstraint property to true. However, this is not
> recommended.
>
> Since the ProductCode field doesn't allow null value, it's better for us
> to
> add a control to input data for it.
>
> Kevin Yu
> =======
> "This posting is provided "AS IS" with no warranties, and confers no
> rights."
>



 
Reply With Quote
 
Kevin Yu [MSFT]
Guest
Posts: n/a
 
      15th Nov 2005
Hi Vayse,

Thanks for your code to reproduce it. I checked your code, to walkaround
this issue, you have to validate the content of the ProductCode TextBox
when adding a new row. You can handle the ProductCodeTextBox.Validating
event to achieve this.

Private Sub ProductCodeTextBox_Validating(ByVal sender As
System.Object, ByVal e As System.ComponentModel.CancelEventArgs) Handles
ProductCodeTextBox.Validating
If Me.ProductCodeTextBox.Text = String.Empty Then
e.Cancel = True
MessageBox.Show("No Product Code!")
End If
End Sub

Kevin Yu
=======
"This posting is provided "AS IS" with no warranties, and confers no
rights."

 
Reply With Quote
 
Vayse
Guest
Posts: n/a
 
      15th Nov 2005
Thanks, that will do the trick.

"Kevin Yu [MSFT]" <v-(E-Mail Removed)> wrote in message
news:$hH$(E-Mail Removed)...
> Hi Vayse,
>
> Thanks for your code to reproduce it. I checked your code, to walkaround
> this issue, you have to validate the content of the ProductCode TextBox
> when adding a new row. You can handle the ProductCodeTextBox.Validating
> event to achieve this.
>
> Private Sub ProductCodeTextBox_Validating(ByVal sender As
> System.Object, ByVal e As System.ComponentModel.CancelEventArgs) Handles
> ProductCodeTextBox.Validating
> If Me.ProductCodeTextBox.Text = String.Empty Then
> e.Cancel = True
> MessageBox.Show("No Product Code!")
> End If
> End Sub
>
> Kevin Yu
> =======
> "This posting is provided "AS IS" with no warranties, and confers no
> rights."
>



 
Reply With Quote
 
Kevin Yu [MSFT]
Guest
Posts: n/a
 
      16th Nov 2005
You're welcome.

Kevin Yu
=======
"This posting is provided "AS IS" with no warranties, and confers no
rights."

 
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
Record Navigator problem George Papadopoulos Microsoft Access Form Coding 1 29th Apr 2004 08:32 AM
Bindings problem JezB Microsoft Dot NET Framework Forms 0 7th Apr 2004 04:50 PM
Netscape Navigator application has encountered a problem EL Windows XP General 3 1st Mar 2004 07:44 PM
Adapters and Bindings Connection Order Problem Mike McCollister Windows XP Networking 0 10th Nov 2003 01:23 PM
Help. Need fix for bindings problem Jim Campbell Windows XP Networking 0 18th Aug 2003 11:00 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 12:05 AM.