[RESOLVED] Confusion about Binding Source and changing row values from code vs bound controls
[edit]oops - stupid typo - this is resolved and explained in the next post[/edit]
I've got a BINDING SOURCE - that I bind to controls - textboxes mostly.
I create a row in the datatable behind this BINDING SOURCE like this.
Code:
If clientnewBS.Filter <> "CaseId=99999999" Then
clientnewBS.AddNew()
Dim drv As DataRowView = TryCast(clientnewBS.AddNew(), DataRowView)
drv("CaseId") = "99999999"
drv("SalesAssoc") = CMCUser
drv.EndEdit()
clientnewBS.Filter = "CaseId=99999999"
End If
I can see that the BS has a single row and that the datatable behind this BS also has a single row after this is done.
After this the user is allowed to enter data into textboxes associated with this new client record as well.
Basically after they click SAVE we create a new case - and get back the CASE ID (identity column on another table that's primary to this whole process).
My goal is to change the PK of this new client row from the 99999999 fixed value we have had all along to the PK IDENT value from the primary table.
Code:
caseBAL_C.StateFlag = CSFlags.Add
caseBS.Filter = ""
Dim drv As DataRowView = TryCast(caseBS.AddNew(), DataRowView)
drv("CaseId") = "99999999"
drv("CaseNum") = ""
drv("DateLoaded") = Date.Now
drv("Status1") = ""
drv("Status2") = "C"
drv("ClientId") = BDVclientid
drv("MatterNumber") = BDVMatterNumber.Text
drv("PatentApp") = BDVPatentApp.Text
drv("CaseType") = BDVType
drv("SubType") = BDVSubType.Text
caseBS.EndEdit()
caseBAL_C.StateFlag = CSFlags.Unknown
caseBAL_C.caseUpdate()
BDVCaseId = drv("CaseId").ToString
caseBS.Filter = "CaseId=" & BDVCaseId
Dim drv2 As DataRowView = TryCast(clientnewBS.Current, DataRowView)
drv2("CaseId") = BDVCaseId
drv2.EndEdit()
clientnewBS.Filter = "CaseId=" & BDVCaseId
clientnewBS.EndEdit()
clientBAL_C.clientnewUpdate()
The first part of that code creates the new CASE record - and after the caseBAL_C.caseUpdate is called I get the NEW CASE ID value.
Then I want to change the NEW CLIENT ROW's PK to match this CASE ID.
I tried it through the TEXTBOX that's bound - and also with the method above. What's happening is it's creating a second row in the datatable behind the BS.
Why is that??
Re: Confusion about Binding Source and changing row values from code vs bound control
Never mind - I fixed it - stupid typo
Code:
If clientnewBS.Filter <> "CaseId=99999999" Then
clientnewBS.AddNew()
Dim drv As DataRowView = TryCast(clientnewBS.AddNew(), DataRowView)
drv("CaseId") = "99999999"
drv("SalesAssoc") = CMCUser
drv.EndEdit()
clientnewBS.Filter = "CaseId=99999999"
End If
I was callign the .AddNew() twice above - didn't uncover that until I started debugging further and further back in the logic to see where the "2 rows" were coming from - and this is exacly where they came from!
oops