Wrox Programmer Forums
Go Back   Wrox Programmer Forums > ASP.NET and ASP > ASP.NET 4 > ASP.NET 4 General Discussion
|
ASP.NET 4 General Discussion For ASP.NET 4 discussions not relating to a specific Wrox book
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ASP.NET 4 General Discussion section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old December 28th, 2011, 12:29 PM
Registered User
 
Join Date: Dec 2011
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
Default How can I capture the Sql error 547 in Entity Data Source

Dear All,

Need your assistance
I am trying to capture this error 547 (The DELETE statement conflicted with the REFERENCE constraint "FK_iCategorySub_iCategory") and informing the user that this record has associated record in another table. FYI I am using Entity Data Source for my List View. In SQL Data Source I could use “SqlDataSourceStatusEventArgs” and it works successfully.

Many thanks and best regards

Last edited by jeffrianwar; December 28th, 2011 at 07:16 PM..
 
Old December 29th, 2011, 03:58 AM
Imar's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
Default

Hi there,

You can handle the Deleted event of the ODS and then look at the InnerException of the Exception property on the e argument. Something like this should do the trick:

Code:
protected void EntityDataSource1_Deleted(object sender, EntityDataSourceChangedEventArgs e)
{
  if (e.Exception != null && e.Exception.InnerException != null && e.Exception.InnerException is SqlException)
  {
    SqlException myException = (SqlException)e.Exception.InnerException;
    if (myException.Number == 547)
    {
      ErrorMessage.Text = @"Sorry, you can't delete this record because it has associated records that you need to delete first.";
      e.ExceptionHandled = true;
    }
  }
}
Hope this helps,

Imar
__________________
Imar Spaanjaars
http://Imar.Spaanjaars.Com
Follow me on Twitter

Author of Beginning ASP.NET 4.5 : in C# and VB, Beginning ASP.NET Web Pages with WebMatrix
and Beginning ASP.NET 4 : in C# and VB.
Did this post help you? Click the button below this post to show your appreciation!
 
Old December 29th, 2011, 06:20 AM
Registered User
 
Join Date: Dec 2011
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
Smile Many thanks...

Dear Imar,

Many thanks, sure it help.

Take care, you have a great week-end and happy new year...





Similar Threads
Thread Thread Starter Forum Replies Last Post
Entity Data Source and bit data types DennisE ASP.NET 4 General Discussion 5 July 25th, 2011 02:51 PM
Unable to select Entity in Data Source Configuration Wizard kuldeepty BOOK: Beginning ASP.NET 4 : in C# and VB 7 December 3rd, 2010 03:40 PM
confusing in ADO.NET Entity Data Model,Linq to sql angelboy ADO.NET 5 November 21st, 2008 05:01 PM
Capture Sql server Error happygv SQL Server 2000 19 May 10th, 2007 12:55 AM
data source and SQL queries sss22 ASP.NET 1.0 and 1.1 Basics 1 October 24th, 2005 01:13 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.