Wrox Home  
Search P2P Archive for: Go

  Return to Index  

aspx_professional thread: Could someone please explain the following behavior to me?


Message #1 by joliver@n... on Fri, 14 Dec 2001 18:26:57
I agree with you that you should NOT be able to reference the Table object after setting the DataSet =
nothing.

The only reason I can think of that this would work would be that garbage collection has not run yet.  If this is the case, then
objTable would still be point to a valid object (for how long, who knows).

Anyone else have any ideas?  Am I way off?

Thanks,

Steve



ASPX_Professional <aspx_professional@p...> wrote:
> When you state:
obj1 = obj2
 in most cases you will end up with totally independent objects.

This is not the case of  datatables and data rows.  The reason for that is
that whithin the table object, there is a property that defines the table
name and another property that defines which data set the table belongs to.
So when you state Table1 = Table2, both references refer to the same data.

There will be times when you will want a totally independent table, and in
that case, you will need to make a clone or a copy of the first table.  The
clone function provides a data table with the same scheme, but no data.

Table1 = table2.clone()
Table1 = table2.copy()


I hope this answers your question.

Also, you should not have a problem with:
objNewRow = objDataSet.Tables("Employees").NewRow()
(remember to add objNewRow to the table before the databind statement.)

rgds,
Octavio



-----Original Message-----
From: joliver@n... [mailto:joliver@n...]
Sent: Friday, December 14, 2001 6:27 PM
To: ASPX_Professional
Subject: [aspx_professional] Could someone please explain the following
behavior to me?


The following is a pretty much verbatim example from the beginning asp.net
with vb.net book. It's straightforward, and not really worth talking about
in and of itself. However, I have a question about the overall .net
framework thats quite confusing (to me).

I asked previously why this code block works. I was told that you're still
able to reference the objTable object after setting the objDataSet object
to nothing because it's not a pointer to the objDataSet object, but
instead that it's a full fledged *copy* of the object, in line with the
entire 'disconnected data' theme.

    dim objTable as DataTable
    dim objNewRow as DataRow

    objTable = objDataSet.Tables("Employees")
    objDataSet = Nothing
    objNewRow = objTable.NewRow()
    objNewRow.Item("FirstName") = "Norman"
    objNewRow.Item("LastName") = "Blake"
    objTable.Rows.Add(objNewRow)
    dgNameList2.DataSource = objTable.DefaultView
    dgNameList2.DataBind()

So far so good, and I could live with this behavior no problem. However,
the next code block demonstrates that in fact, what happens to objTable
does in fact happen to objDataSet as well.

    objTable = objDataSet.Tables("Employees")
    objNewRow = objTable.NewRow()
    objNewRow.Item("FirstName") = "Norman"
    objNewRow.Item("LastName") = "Blake"
    objTable.Rows.Add(objNewRow)
    dgNameList2.DataSource = objTable.DefaultView
    dgNameList2.DataBind()
    dgNameList3.DataSource = objDataSet.Tables("Employees").DefaultView
    dgNameList3.DataBind()

I can't reconcile these two behaviors, could someone who understands this
take the time to explain it to me? If you want to try this yourself, the
DataSet.Tables("Employees") is populated from the default Northwind
employees database.

Additionally, is there any particular reason why I can't do the following?

     objNewRow = objDataSet.Tables("Employees").NewRow()






$subst('Email.Unsub').




  Return to Index