Link to home
Start Free TrialLog in
Avatar of R_a_V_e_N
R_a_V_e_N

asked on

SQL error 547...

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!
Avatar of iboutchkine
iboutchkine

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
ASKER CERTIFIED SOLUTION
Avatar of Mohammed Nasman
Mohammed Nasman
Flag of Palestine, State of image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of R_a_V_e_N

ASKER

Thanks for ur help guys!!!

both answers were good, unfortunately I can only accept one answer :(
I think you gave more details, so I decided to accept ur answer!!!