Results 1 to 4 of 4

Thread: Odd BindingContext behavior

  1. #1

    Thread Starter
    New Member KHolden's Avatar
    Join Date
    Jul 2002
    Posts
    9

    Odd BindingContext behavior

    I have a form with a dataset bound to a datagrid and several textbox controls. I can navigate my data with ease and perform updates but for some reason when I add a new datarow using BindingContext.AddNew, although the BindingContext.Count gets incremented I cannot reference the actual row at that location - it errors out saying there is no row.

    Here's sample code:
    VB Code:
    1. With tArbiter
    2.             .Columns("ID").DefaultValue = Guid.NewGuid
    3.             .Columns("ArbiterKey").DefaultValue = ArbiterID
    4.             .Columns("FirmKey").DefaultValue = rLawFirm(iFirmPos).Item("ID")
    5.             .Columns("FirmName").DefaultValue = rLawFirm(iFirmPos).Item("FirmName").ToString
    6.             .Columns("CreationDate").DefaultValue = Date.Today
    7.             .Columns("LastUpdate").DefaultValue = Date.Today
    8.             .Columns("StartDate").DefaultValue = Date.Today
    9.         End With
    10.         Console.WriteLine("Before: " & BindingContext(dsArbiters, tnArbiter).Position.ToString)
    11.         BindingContext(dsArbiters, tnArbiter).AddNew()
    12.         Console.WriteLine("After: " & BindingContext(dsArbiters, tnArbiter).Position.ToString)

    Now the console writelines show the position gets incremented but any referencing to new row fails.

    I've been pulling my hair out on this one... anyone have any insight?

    ~/<at

    ~~~~~~~~~~~~~~~
    There is a certain satifaction in living a life in complete and total failure.
    - Edward Abbey

  2. #2
    Banished Cander's Avatar
    Join Date
    Dec 2000
    Location
    Why do you care?
    Posts
    6,913
    this is just a shot in the dark..but maybe if you use

    yourdataset.AcceptChanges()

    Stack Overflow
    See the features of Visual Studio 2010 and C# 4.0: The 10-4 show on Channel9

  3. #3

    Thread Starter
    New Member KHolden's Avatar
    Join Date
    Jul 2002
    Posts
    9
    Although I tried AcceptChanges as a kludge (and it failed) that wouldn't be a real solution anyway since it would mark the row as current and remove it from actually being written out during an update.

    When I dug into the structures I found that the new DataRow is being created as System.Data.DataRowState = Detached. I'm at a loss as to know why but that state seems to mean it's getting created but never actually added to my dataset...

  4. #4

    Thread Starter
    New Member KHolden's Avatar
    Join Date
    Jul 2002
    Posts
    9

    Thumbs up

    Ok, figured it out... the dataset is based on multitable query which apparently makes the command builder toss it's cookies. As a result, the AddNew() call was unable to directly add the row and instead was tossing it off into detacho land.

    I manually coded the SQL select/update/add/delete commands and all is well again with the world...

    ~/<at


    ~~~~~~~~~~~~~~~
    Last night you were, unhinged. You were like some desperate, howling demon. You frightened me.
    ...Do it again.
    - Morticia Addams

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