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(" @CustomerI D", SqlDbType.NChar, 5, "CustomerID");
cmdDelete.Parameters["@Cus tomerID"]. SourceVers ion = 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!
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("
cmdDelete.Parameters["@Cus
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!
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
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thanks for ur help guys!!!
both answers were good, unfortunately I can only accept one answer :(
both answers were good, unfortunately I can only accept one answer :(
ASKER
I think you gave more details, so I decided to accept ur answer!!!