C# 使用表值参数更新datatable
我不熟悉表值参数。我有两张桌子:Businessparent和Businessdetailchild。有一列:business_id,它是business表的主键,也是businessdetail的外键。两个表之间的关系:C# 使用表值参数更新datatable,c#,sql-server,table-valued-parameters,C#,Sql Server,Table Valued Parameters,我不熟悉表值参数。我有两张桌子:Businessparent和Businessdetailchild。有一列:business_id,它是business表的主键,也是businessdetail的外键。两个表之间的关系: ds.Relations.Add(new DataRelation("Business_BusinessDetail", ds.Tables["Business"].Columns["Business_ID"],ds.Tables["BusinessDetail"].Colu
ds.Relations.Add(new DataRelation("Business_BusinessDetail", ds.Tables["Business"].Columns["Business_ID"],ds.Tables["BusinessDetail"].Columns["Business_ID"]));
现在,在使用表值参数插入父表时,我想在插入子表之前更新主键。我的代码:
//母公司
SqlParameter tvpParamparent = insertCmd.Parameters.AddWithValue("@Business", newBusinessDS.Tables["Business"]);//Needed TVP
tvpParamparent.SqlDbType = SqlDbType.Structured;
insertCmd.ExecuteNonQuery();-->does not update business_id
//孩子
SqlParameter tvpParamchild = insCmdChild.Parameters.AddWithValue("@BusinessDetail", newBusinessDS.Tables["BusinessDetail"]);
tvpParamchild.SqlDbType = SqlDbType.Structured;/
insCmdChild.ExecuteNonQuery();-->it throws an error:"The MERGE statement conflicted with the FOREIGN KEY constraint "FK_BusinessDetail_Business""
不要在参数名称中使用@字符