B
brianm
Hello, I have a simple ADO.NET question for someone who knows their
stuff. This has been bugging me.
Here's the basic question: What is going on behind the scenes when I
create a detached datarow and then call datarow.table.add? What's being
accessed there?
It isn't attached to a table, so is .net creating a table on the fly,
or does it automatically create a dataset and a datatable for it behind
the scenes? Or is something else going on?
Here's an example of something weird that I did that, oddly, works.
1) I create a detached datarow with datatable.NewRow ...I can call
datarow.rowstate and see that it's detached.
Also, the datatable falls out of scope because it's in a function in a
data object. So that datatable is out of the picture.
2) I modify the datarow. Maybe I change a text field or something.
3) I want to save my changes, so I need to add it to a data table and
use an adapter's update method. So, normally I'd instantiate a new
datatable and do datatable.add, but here's the thing. I can actually
call, /on the detached datarow/, the following lines of code:
thisRow.Table.Rows.Add(thisRow)
thisAdapter.update(thisRow)
And it works! What is going on here? Did the table already exist
because .net created a dataset and datatable behind the scenes, or did
I just create a new table?
Thanks in advance,
Brian MacKay
stuff. This has been bugging me.
Here's the basic question: What is going on behind the scenes when I
create a detached datarow and then call datarow.table.add? What's being
accessed there?
It isn't attached to a table, so is .net creating a table on the fly,
or does it automatically create a dataset and a datatable for it behind
the scenes? Or is something else going on?
Here's an example of something weird that I did that, oddly, works.
1) I create a detached datarow with datatable.NewRow ...I can call
datarow.rowstate and see that it's detached.
Also, the datatable falls out of scope because it's in a function in a
data object. So that datatable is out of the picture.
2) I modify the datarow. Maybe I change a text field or something.
3) I want to save my changes, so I need to add it to a data table and
use an adapter's update method. So, normally I'd instantiate a new
datatable and do datatable.add, but here's the thing. I can actually
call, /on the detached datarow/, the following lines of code:
thisRow.Table.Rows.Add(thisRow)
thisAdapter.update(thisRow)
And it works! What is going on here? Did the table already exist
because .net created a dataset and datatable behind the scenes, or did
I just create a new table?
Thanks in advance,
Brian MacKay