Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium


SQL error 547...

Posted on 2003-03-08
Medium Priority
Last Modified: 2011-09-20

Iam experimenting with the ADO.NET. I tried creating a simple Windows based sample application, from which a user can create, modify, and delete rows (data) of Northwind  database through DataGrid.

I can easily add new rows, modify rows but when I try to delete rows SqlException gets thrown. After I handle exception, the following error appears:
SQL Error 547: Delete statement conflicted with COLUMN REFERENCE constaint 'FK_Orders_Customers'. The conflict occured in database 'Northwind', table 'Orders', column 'CustomerID'.

Why is it giving me this error??? when Iam not even using Orders table, Iam using Customers table. btw, here is my code:

//cnn = SqlConnection
SqlCommand cmdDelete = cnn.CreateCommand();
               cmdDelete.CommandType = CommandType.Text;
                    cmdDelete.CommandText = "DELETE FROM Customers WHERE CustomerID = @CustomerID";
                    cmdDelete.Parameters.Add("@CustomerID", SqlDbType.NChar, 5, "CustomerID");
                    cmdDelete.Parameters["@CustomerID"].SourceVersion = DataRowVersion.Original;

Iam fairly new with ADO.NET, I would appreciate it if someone could tell me the cause of my problem and give me a solution.

Thanks a million!
Question by:R_a_V_e_N
  • 2
LVL 28

Expert Comment

ID: 8093801
It looks like you violating referentiol integrity. Check if you have relationshops between Orders and Customers. It might be the child record that you cannot delete until you have deleted the paren record
LVL 22

Accepted Solution

Mohammed Nasman earned 200 total points
ID: 8093812

  I think this error for "Constraint violation", seems you are trying to Delete record in Customers table that has details in other tables, if you want to delete from the master, you should first delete it's details records from the detail table, for example if the cusomter table has detail called orders, first delete the records for the cusomter in detail table before you delete it from the master

Best regards
Mohammed Nasman

Author Comment

ID: 8095040
Thanks for ur help guys!!!

both answers were good, unfortunately I can only accept one answer :(

Author Comment

ID: 8095046
I think you gave more details, so I decided to accept ur answer!!!

Featured Post

Nothing ever in the clear!

This technical paper will help you implement VMware’s VM encryption as well as implement Veeam encryption which together will achieve the nothing ever in the clear goal. If a bad guy steals VMs, backups or traffic they get nothing.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This document covers how to connect to SQL Server and browse its contents.  It is meant for those new to Visual Studio and/or working with Microsoft SQL Server.  It is not a guide to building SQL Server database connections in your code.  This is mo…
A long time ago (May 2011), I have written an article showing you how to create a DLL using Visual Studio 2005 to be hosted in SQL Server 2005. That was valid at that time and it is still valid if you are still using these versions. You can still re…
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an anti-spam), the admin…
Enter Foreign and Special Characters Enter characters you can't find on a keyboard using its ASCII code ... and learn how to make a handy reference for yourself using Excel ~ Use these codes in any Windows application! ... whether it is a Micr…
Suggested Courses

577 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question