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!