PC Review


Reply
Thread Tools Rate Thread

Dataset Constraints - again

 
 
Woody Splawn
Guest
Posts: n/a
 
      3rd Aug 2005
Last week sometime I posted the message below but I, unfortunately, have not
yet received an answer to the problem. The question has to do with how to
intercept a constraint viloation message in code and give the user a
different message. Someone responed by saying that I should use a try catch
statement, which is obvious, but the question is, where do I place it?
Where do I place such a try catch or some other code to catch a constraint
violation before VS shows the default message. The original question
follows:

A question please.

Lets say I have a grid with its datasource as a dataset with three columns
in it; UserID (an auto generated ID), LastName and FirstName. Additionally,
lets say I want to restrict the user from entering two records with the same
last name and first name. I have created a constraint for LastName
FirstName in the dataset but I would like a different message than the
default message I get when the constraint is violated. Is there a way for
me to do this?


 
Reply With Quote
 
 
 
 
AMDRIT
Guest
Posts: n/a
 
      3rd Aug 2005
Have a look at:

ms-help://MS.VSCC.2003/MS.MSDNQTR.2003FEB.1033/cpref/html/frlrfSystemDataCommonDbDataAdapterClassFillErrorTopic.htm

Here is what I have been doing.

Public Function GetAddressesList() As DataDictionary

Dim ds As DataDictionary
ds = New DataDictionary

Try
daAddresses.Fill(ds.Addresses)
ds.Addresses.PrimaryKey = New DataColumn()
{ds.Addresses.Columns("AddressID")}
Catch ex As System.Data.ConstraintException 'Ignore this exception

Catch ex As Exception
Throw New ApplicationException("Unable to fetch ""Addresses""", ex)
End Try
Return ds

End Function


'Synchronizes local Address changes with the SQL server
Private Sub UpdateAddresses(ByVal AddressChanges As DataDictionary)


'Handle row inserts, sync identity updates
AddHandler AddressChanges.Addresses.ColumnChanging, New
DataColumnChangeEventHandler(AddressOf AddressRow_ColumnChanging)
AddHandler daAddresses.RowUpdated, AddressOf AddressRow_RowUpdated
AddHandler daAddresses.FillError, AddressOf Addresses_FillError
Dim iRet As Integer

'Update the local changes with the SQL database
iRet = daAddresses.Update(AddressChanges.Addresses)

'Remove handlers for row inserts and sync identity updates
RemoveHandler daAddresses.FillError, AddressOf Addresses_FillError
RemoveHandler daAddresses.RowUpdated, AddressOf AddressRow_RowUpdated
RemoveHandler AddressChanges.Addresses.ColumnChanging, AddressOf
AddressRow_ColumnChanging

End Sub

"Woody Splawn" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> Last week sometime I posted the message below but I, unfortunately, have
> not
> yet received an answer to the problem. The question has to do with how to
> intercept a constraint viloation message in code and give the user a
> different message. Someone responed by saying that I should use a try
> catch
> statement, which is obvious, but the question is, where do I place it?
> Where do I place such a try catch or some other code to catch a constraint
> violation before VS shows the default message. The original question
> follows:
>
> A question please.
>
> Lets say I have a grid with its datasource as a dataset with three columns
> in it; UserID (an auto generated ID), LastName and FirstName.
> Additionally,
> lets say I want to restrict the user from entering two records with the
> same
> last name and first name. I have created a constraint for LastName
> FirstName in the dataset but I would like a different message than the
> default message I get when the constraint is violated. Is there a way for
> me to do this?
>
>



 
Reply With Quote
 
Woody Splawn
Guest
Posts: n/a
 
      4th Aug 2005
Thank you for responding.

I mean no offense to you or anyone else but man that is complicated for such
an easy thing to do in other tools. I hope others have an opinion or a
simpler way of doing this.

Basically, I want to catch the constraint violation as soon as the user
tries to leave the row of a grid, not just at the time he fills the dataset.

In the Infragistics Ultragrid there is an event that deals with this kind of
thing rather easily [UltraGrid_Error Event]. However, we would like to not
use third party tools unless absolutely necessary. Just thought there might
be a way to do this using native Visual Studio without making a federal case
out of it.

Again, the idea is to catch the constraint violation and deal with it when a
user leaves a row in a grid (or a row in a form for that matter), giving the
user a message other than the stock message provided by Visual Studio.
Example: A row with First Name, Last Name.

I sure hope VS 2005 deals with this and a number of other things like it in
a simpler way.

Woody



 
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
Dataset constraints Woody Splawn Microsoft ADO .NET 2 29th Jul 2005 04:16 PM
Rows.Add and DataSet Constraints Christopher Weaver Microsoft C# .NET 2 1st Jul 2005 01:43 AM
DataSet constraints Glenn Thimmes Microsoft ADO .NET 1 31st May 2005 11:30 AM
DataSet constraints Bert Sachs Microsoft ADO .NET 1 11th May 2004 12:13 PM
Database constraints and dataset constraints Rapi Microsoft ADO .NET 1 24th Dec 2003 12:40 PM


Features
 

Advertising
 

Newsgroups
 


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