473,378 Members | 1,680 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,378 software developers and data experts.

Validating Data Using a Error Provider

A binding navigator control adds the following code for when the Save button is clicked:
Me.Validate()
Me.UserBindingSource.EndEdit()
Me.UserTableAdapter.Update(Me.UserDataSet.User)"

You can add code to the column changing event for the dataset by using the dataset designer, for example:

Private Sub UserDataTable_ColumnChanging(ByVal sender As System.Object, ByVal e As System.Data.DataColumnChangeEventArgs) Handles Me.ColumnChanging
If (e.Column.ColumnName = Me.WindowsLoginColumn.ColumnName) Then
If CType(e.ProposedValue, String) = "" Then
e.Row.SetColumnError(e.Column, "Cannot be blank")
Else
e.Row.SetColumnError(e.Column, "")
End If
End If

The problem is, the validation is not actually done until the .EndEdit event is fired. Me.Validate can be overriden for form validation (not validation on the dataset columns). So EndEdit throws a runtime error say if you have Null for a column that does not allow Nulls. I'm having a very hard time getting my validation to work using the error provider rather than throwing runtime errors. Help!

Jul 5 '06 #1
5 3913
Ok I'm just going to use form validation and column validation I guess (seems silly). How do I return false since the controls_validating is a sub and not a function?
"Ryan" <Ty****@newsgroups.nospamwrote in message news:O%****************@TK2MSFTNGP05.phx.gbl...
A binding navigator control adds the following code for when the Save button is clicked:
Me.Validate()
Me.UserBindingSource.EndEdit()
Me.UserTableAdapter.Update(Me.UserDataSet.User)"

You can add code to the column changing event for the dataset by using the dataset designer, for example:

Private Sub UserDataTable_ColumnChanging(ByVal sender As System.Object, ByVal e As System.Data.DataColumnChangeEventArgs) Handles Me.ColumnChanging
If (e.Column.ColumnName = Me.WindowsLoginColumn.ColumnName) Then
If CType(e.ProposedValue, String) = "" Then
e.Row.SetColumnError(e.Column, "Cannot be blank")
Else
e.Row.SetColumnError(e.Column, "")
End If
End If

The problem is, the validation is not actually done until the .EndEdit event is fired. Me.Validate can be overriden for form validation (not validation on the dataset columns). So EndEdit throws a runtime error say if you have Null for a column that does not allow Nulls. I'm having a very hard time getting my validation to work using the error provider rather than throwing runtime errors. Help!

Jul 5 '06 #2
Hi Ryan,

Thank you for your post.

Based on my understanding, your question is how to use ErrorProvider to
display errors when working with a DataSet. If I've misunderstood anything,
please feel free to post here.

First, please take a look at following MSDN Library article:

#Walkthrough: Adding Validation to a Dataset
http://msdn2.microsoft.com/en-us/library/ms171930.aspx

From this example, we will see that the ErrorProvider is working when you
move focus away from the field. This will give the user a visual clue of
which field is filled wrong value. Also, the validation will only work when
you changed the field's value.

Hope this helps. Please feel free to post here if anything is unclear.

Regards,
Walter Wang (wa****@online.microsoft.com, remove 'online.')
Microsoft Online Community Support

==================================================
When responding to posts, please "Reply to Group" via your newsreader so
that others may learn and benefit from your issue.
==================================================

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

Jul 6 '06 #3
Hi Walter,

I actually used that walkthrough prior to this post. There are 2 problems
with it.
1) If the user put's nothing in the field (leaves it blank), the
ErrorProvider does not appear. If using the ErrorProvider control during
the control's (text box for example) validating event rather than in the
dataset, it works whether the user enters anything or not, it validates when
the control loses focus whereas the dataset column_changing validating event
only occurs if the field has changed.
2) Just because the error provider error is set (using seterror()), it still
does not stop the database update from happening. So if the field contains
something that violates the dataset integrity a runtime error will occur.
Perhaps a try-catch block that does nothing in the catch block is the way to
go (since the ErrorProvider handles informing the user of the input error).

Ryan

"Walter Wang [MSFT]" <wa****@online.microsoft.comwrote in message
news:Ci**************@TK2MSFTNGXA01.phx.gbl...
Hi Ryan,

Thank you for your post.

Based on my understanding, your question is how to use ErrorProvider to
display errors when working with a DataSet. If I've misunderstood
anything,
please feel free to post here.

First, please take a look at following MSDN Library article:

#Walkthrough: Adding Validation to a Dataset
http://msdn2.microsoft.com/en-us/library/ms171930.aspx

From this example, we will see that the ErrorProvider is working when you
move focus away from the field. This will give the user a visual clue of
which field is filled wrong value. Also, the validation will only work
when
you changed the field's value.

Hope this helps. Please feel free to post here if anything is unclear.

Regards,
Walter Wang (wa****@online.microsoft.com, remove 'online.')
Microsoft Online Community Support

==================================================
When responding to posts, please "Reply to Group" via your newsreader so
that others may learn and benefit from your issue.
==================================================

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

Jul 6 '06 #4
Hmmm I tried the try-catch block but it seems the error occurs before the
DataTable_ColumnChanging event occurs (where the validation takes place).
So if a field violates database integrity, nothing happens.

"Ryan" <Ty****@newsgroups.nospamwrote in message
news:%2****************@TK2MSFTNGP03.phx.gbl...
Hi Walter,

I actually used that walkthrough prior to this post. There are 2 problems
with it.
1) If the user put's nothing in the field (leaves it blank), the
ErrorProvider does not appear. If using the ErrorProvider control during
the control's (text box for example) validating event rather than in the
dataset, it works whether the user enters anything or not, it validates
when the control loses focus whereas the dataset column_changing
validating event only occurs if the field has changed.
2) Just because the error provider error is set (using seterror()), it
still does not stop the database update from happening. So if the field
contains something that violates the dataset integrity a runtime error
will occur. Perhaps a try-catch block that does nothing in the catch block
is the way to go (since the ErrorProvider handles informing the user of
the input error).

Ryan

"Walter Wang [MSFT]" <wa****@online.microsoft.comwrote in message
news:Ci**************@TK2MSFTNGXA01.phx.gbl...
>Hi Ryan,

Thank you for your post.

Based on my understanding, your question is how to use ErrorProvider to
display errors when working with a DataSet. If I've misunderstood
anything,
please feel free to post here.

First, please take a look at following MSDN Library article:

#Walkthrough: Adding Validation to a Dataset
http://msdn2.microsoft.com/en-us/library/ms171930.aspx

From this example, we will see that the ErrorProvider is working when you
move focus away from the field. This will give the user a visual clue of
which field is filled wrong value. Also, the validation will only work
when
you changed the field's value.

Hope this helps. Please feel free to post here if anything is unclear.

Regards,
Walter Wang (wa****@online.microsoft.com, remove 'online.')
Microsoft Online Community Support

================================================= =
When responding to posts, please "Reply to Group" via your newsreader so
that others may learn and benefit from your issue.
================================================= =

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


Jul 6 '06 #5
Hi Ryan,

Thank you for your post.

Using the DataTable's ColumnChanging event, it must occur after you changed
the data, so for a default empty field, this event will not be triggered,
thus the ErrorProvider didn't appear. I recommend you take a look at
following article:

#Extending Windows Forms with a Custom Validation Component Library
http://msdn.microsoft.com/library/de...us/dnforms/htm
l/winforms03162004.asp

With this custom validation component library, you can use these validators
and check each validator's IsValid property after you called "Validate"
method in the save button's click event. If any validator is invalid, don't
call remaining "EndEdit" and "TableAdapter.Update".

Hope this helps. Please feel free to post here if anything is unclear.
Regards,
Walter Wang (wa****@online.microsoft.com, remove 'online.')
Microsoft Online Community Support

==================================================
When responding to posts, please "Reply to Group" via your newsreader so
that others may learn and benefit from your issue.
==================================================

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

Jul 7 '06 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Craig Beuker | last post by:
Hello, I am experimenting with this XmlValidatingReader and have a question about how it is working (or not working as would be the case) The sample documents and code are included at the end...
2
by: Harrie Verveer | last post by:
Hi, I'm building quiet a large webapplication (CMS) in ASP.NET. On localhost the application runs fine. For publishing we use 2 hosting providers at the moment (let's call those 'A' and 'B')....
5
by: petro | last post by:
Hello all, My asp.net web application works on my machine but I get the following error on our test web server, There is only one oracle home on the test server. Does anyone know how to resolve...
0
by: Gary Shell | last post by:
I am experiencing some strange behavior between a UserControl's validating event and a treeview control. Initially, I thought it was related to an issue in the Knowledgebase article 810852...
0
by: acwomble | last post by:
I am working with a database on another system via a ssh tunnel using plink. We have setup an alias the local system for the remote database. I am able to connect and work from within Visual...
4
by: easoftware | last post by:
I am using VS .Net 2003 and VB. I have an app with one parent and two Mdi child forms. I need to validate data in the Mdi form. The Form.Validating event works when I try to close a Mdi form,...
0
by: mk397 | last post by:
Hello, I'm new to this site and after reading through many posts decided to join. I have a problem with my basic login page. After I type in the login info I get the following error: ...
2
by: Peted | last post by:
Hi if i derive a reference to a control on a winform (ie Control activeControl = somecontrol on the form) how can i test if that control has a validating or validated event and more importantly...
8
ammoos
by: ammoos | last post by:
Hi Friends I am getting the following error when I am trying to read data from an excel sheet using sql script OLE DB provider 'Microsoft.Jet.OLEDB.4.0' reported an error. The provider did not...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.