我有一个程序,我正在将数据写入 datagridviews,当我关闭表单时,数据会保存到 SQL Server 数据库中。但是当它有子行时,我在删除父行时遇到问题。我收到并发冲突异常。当我检查数据库时,我看到只删除了子行。
这是我创建 SQL Server 表的查询:
sql = "CREATE TABLE Auto("
+ "VIN varchar(10) NOT NULL PRIMARY KEY,"
+ "Make nvarchar(50),"
+ "Model nvarchar(50),"
+ "Year smallint);";
和
sql = "CREATE TABLE Repair("
+ "ID int NOT NULL PRIMARY KEY,"
+ "VIN varchar(10) NOT NULL,"
+ "Description nvarchar(255),"
+ "Cost float)"
+ "ALTER TABLE Repair ADD FOREIGN KEY (VIN) REFERENCES Auto(VIN) ON DELETE CASCADE;";
我正在通过SqlDataAdapter
.