Two datagrids [Header-detail] insert problem

  • Thread starter Thread starter Agnes
  • Start date Start date
A

Agnes

I can bind to both datagrid succesfully, However, if i only want to insert a
new row in header table, it fails, it seems I must insert detail table also.

--------------------------formload----
dsSeaExHBL_cntrmark.Clear()
daSeaExHBL_cntrmark.SelectCommand = New SqlCommand()
daSeaExHBL_cntrmark.SelectCommand.Connection = conSea
daSeaExHBL_cntrmark.TableMappings.Add("Table",
"BillLadingContainer")
daSeaExHBL_cntrmark.SelectCommand.CommandText = "select * from
billladingcontainer where number ='" & Trim(Me.pHBLNo) & "' order by
billladingcontainer.seqno "
daSeaExHBL_cntrmark.Fill(dsSeaExHBL_cntrmark,
"billladingcontainer")
daSeaExHBL_cntrmark.SelectCommand.CommandText = "select * from
billladingmarking where number ='" & Trim(Me.pHBLNo) & "' order by
billladingmarking.seqno "
daSeaExHBL_cntrmark.Fill(dsSeaExHBL_cntrmark, "billladingmarking")

Dim cb as commandbuilder(daSeaExHBL_cntrmark)

--------save----
Dim drCntr As DataRow =
dsSeaExHBL_cntrmark.Tables("BillLadingContainer").NewRow()

drCntr("number") = Trim(Me.pHBLNo)
drCntr("containerno") = Trim(Me.txtCntrNo.Text)
drCntr("filterkey") = Trim(Me.pHBLNo) & "@" &
CType(Me.txtSeqNo.Text, String) & "@" & Trim(Me.txtCntrNo.Text)
drCntr("sealno") = Trim(Me.txtSealno.Text)


dsSeaExHBL_cntrmark.Tables("BillLadingContainer").Rows.Add(drCntr)

daSeaExHBL_cntrmark.Update(dsSeaExHBL_cntrmark)<--- it return error. It said
i didn't insert marking.
[If I only want to insert a record in header, how can i do that ??]
Thanks a lot
 
Thanks for Cor 's mail
For such issue, I separate into two different adapator , and it works fine.
 
Hi Agnes,

It is very difficult reading, maybe you can bring it next time when you send
it more eaiser to read changing your special names to more general, that
makes helping more easy.

When you have more tables in your dataset you have to tell which datatable
to update, I think as wel that it is in your situation better to make for
now for each table its own datadapter.

That makes it easier to use for each select (table) an own commandbuilder.

I hope this helps?

Cor

(By accident sended by mail)
 
Back
Top