|
-
Aug 8th, 2002, 10:17 PM
#1
Thread Starter
New Member
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:
With tArbiter
.Columns("ID").DefaultValue = Guid.NewGuid
.Columns("ArbiterKey").DefaultValue = ArbiterID
.Columns("FirmKey").DefaultValue = rLawFirm(iFirmPos).Item("ID")
.Columns("FirmName").DefaultValue = rLawFirm(iFirmPos).Item("FirmName").ToString
.Columns("CreationDate").DefaultValue = Date.Today
.Columns("LastUpdate").DefaultValue = Date.Today
.Columns("StartDate").DefaultValue = Date.Today
End With
Console.WriteLine("Before: " & BindingContext(dsArbiters, tnArbiter).Position.ToString)
BindingContext(dsArbiters, tnArbiter).AddNew()
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
-
Aug 9th, 2002, 10:38 AM
#2
-
Aug 9th, 2002, 11:56 AM
#3
Thread Starter
New Member
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...
-
Aug 9th, 2002, 12:23 PM
#4
Thread Starter
New Member
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|