?
Solved

SQL error 547...

Posted on 2003-03-08
4
Medium Priority
?
3,570 Views
Last Modified: 2011-09-20
Hello,

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!
0
Comment
Question by:R_a_V_e_N
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
4 Comments
 
LVL 28

Expert Comment

by:iboutchkine
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
0
 
LVL 22

Accepted Solution

by:
Mohammed Nasman earned 200 total points
ID: 8093812
Hello

  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
0
 

Author Comment

by:R_a_V_e_N
ID: 8095040
Thanks for ur help guys!!!

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

Author Comment

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

Featured Post

NFR key for Veeam Backup for Microsoft Office 365

Veeam is happy to provide a free NFR license (for 1 year, up to 10 users). This license allows for the non‑production use of Veeam Backup for Microsoft Office 365 in your home lab without any feature limitations.

Question has a verified solution.

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

The object model of .Net can be overwhelming at times – so overwhelming that quite trivial tasks often take hours of research. In this case, the task at hand was to populate the datagrid from SQL Server database in Visual Studio 2008 Windows applica…
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
If you’ve ever visited a web page and noticed a cool font that you really liked the look of, but couldn’t figure out which font it was so that you could use it for your own work, then this video is for you! In this Micro Tutorial, you'll learn yo…
This tutorial will teach you the special effect of super speed similar to the fictional character Wally West aka "The Flash" After Shake : http://www.videocopilot.net/presets/after_shake/ All lightning effects with instructions : http://www.mediaf…
Suggested Courses

752 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