Results 1 to 2 of 2

Thread: [RESOLVED] Confusion about Binding Source and changing row values from code vs bound controls

  1. #1

    Thread Starter
    MS SQL Powerposter szlamany's Avatar
    Join Date
    Mar 2004
    Location
    Connecticut
    Posts
    18,263

    Resolved [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??
    Last edited by szlamany; Sep 6th, 2009 at 02:51 PM.

    *** Read the sticky in the DB forum about how to get your question answered quickly!! ***

    Please remember to rate posts! Rate any post you find helpful - even in old threads! Use the link to the left - "Rate this Post".

    Some Informative Links:
    [ SQL Rules to Live By ] [ Reserved SQL keywords ] [ When to use INDEX HINTS! ] [ Passing Multi-item Parameters to STORED PROCEDURES ]
    [ Solution to non-domain Windows Authentication ] [ Crazy things we do to shrink log files ] [ SQL 2005 Features ] [ Loading Pictures from DB ]

    MS MVP 2006, 2007, 2008

  2. #2

    Thread Starter
    MS SQL Powerposter szlamany's Avatar
    Join Date
    Mar 2004
    Location
    Connecticut
    Posts
    18,263

    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

    *** Read the sticky in the DB forum about how to get your question answered quickly!! ***

    Please remember to rate posts! Rate any post you find helpful - even in old threads! Use the link to the left - "Rate this Post".

    Some Informative Links:
    [ SQL Rules to Live By ] [ Reserved SQL keywords ] [ When to use INDEX HINTS! ] [ Passing Multi-item Parameters to STORED PROCEDURES ]
    [ Solution to non-domain Windows Authentication ] [ Crazy things we do to shrink log files ] [ SQL 2005 Features ] [ Loading Pictures from DB ]

    MS MVP 2006, 2007, 2008

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width