Dim pd As DataTable '主表表
Dim od As DataTable '明细表
Dim od2 As DataTable '排产总表
Dim cmd As New SqlCommand()
cmd.C
Try
cmd.BeginTransaction()
cmd.CommandText = "Selec t * Fro m 排产登记表_主表 Wher e [_identify] Is Null" '无需加载任何数据
pd = cmd.ExecuteReader(True)
cmd.CommandText = "Selec t * Fro m 排产登记表_明细 Wher e [_identify] Is Null"
od = cmd.ExecuteReader(True)
Dim dr As DataRow = pd.AddNew() '增加一个订单,注意无需给新增行指定OrderID.
Dim localtr As Row =Tables("排产登记表_主表").Current
dr("单据编号") = localtr("单据编号")
dr("登记员") = localtr("登记员")
dr("登记日期") = localtr("登记日期")
dr("备注")=localtr("备注")
dr("审核结果")="待审核"
pd.Save() '必须提前保存主表表, 这样主表ID列的值才是实际生成的主键值.
For Each r As Row In Tables("排产登记表_明细").Rows
Dim tr = od.AddNew() '增加订单明细
tr("_SortKey")=r("_SortKey") ‘就这行数据 保存后在后台看数据发现_SortKey是没有数据的
tr("商品编号")=r("商品编号")
tr("排产目的")=r("排产目的")
tr("生产数量")=r("生产数量")
tr("最低数量")=r("最低数量")
tr("最多数量")=r("最多数量")
tr("打托")=r("打托")
tr("控数")=r("控数")
tr("备注")=r("备注")
tr("父表ID")=dr("_identify") '将自动生成的ID赋值给新增的订单明细
Next
od.save()