Re: Dataset Constraints - again by AMDRIT
AMDRIT
Wed Aug 03 11:41:14 CDT 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" <NospamwoodyS@jts.bz> wrote in message
news:eukoMgEmFHA.1232@TK2MSFTNGP15.phx.gbl...
> 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?
>
>