By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
432,463 Members | 774 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 432,463 IT Pros & Developers. It's quick & easy.

Session Variables Strange Behaviour

P: n/a
Hi all,
I'm having a problem with session variables in vs .net 2003. I start by
doing this:
If Not IsPostBack Then
Dim dt As DataTable
Me.daAlias.Fill(Me.DsPhysicalAlias)
dt = Me.DsPhysicalAlias.Tables(0)
Session("tblAlias") = dt
Session("tblAliasOriginal") = dt
BindGrid()
End If
I want to load dt into two session variables, make whatever changes I want
to tblAlias, and then, compare it with tblAliasOriginal, to see the changes
I've made.
I have a datagrid to make changes to tblAlias and I delete a row using:

Dim dtAlias As DataTable
dtAlias = Session("tblAlias")
dtAlias.Rows(e.Item.ItemIndex).Delete()
dtAlias.AcceptChanges()

Session("tblAlias")
BindGrid()
My problem is that when I delete a row in tblAlias, that row is also deleted
from tblAliasOriginal! Why? How can I prevent this?
Mar 14 '06 #1
Share this Question
Share on Google+
1 Reply


P: n/a
Both session variables are pointing to the same object. There is only ever
1 object in memory - and both tblAlias and tblAliasOriginal are pointing to
it.

I recommend you read up on object references, and what it is to be a
reference type versus a value type.

"Nuno Carvalho" <Nuno Ca******@discussions.microsoft.com> wrote in message
news:AF**********************************@microsof t.com...
Hi all,
I'm having a problem with session variables in vs .net 2003. I start by
doing this:
If Not IsPostBack Then
Dim dt As DataTable
Me.daAlias.Fill(Me.DsPhysicalAlias)
dt = Me.DsPhysicalAlias.Tables(0)
Session("tblAlias") = dt
Session("tblAliasOriginal") = dt
BindGrid()
End If
I want to load dt into two session variables, make whatever changes I want
to tblAlias, and then, compare it with tblAliasOriginal, to see the
changes
I've made.
I have a datagrid to make changes to tblAlias and I delete a row using:

Dim dtAlias As DataTable
dtAlias = Session("tblAlias")
dtAlias.Rows(e.Item.ItemIndex).Delete()
dtAlias.AcceptChanges()

Session("tblAlias")
BindGrid()
My problem is that when I delete a row in tblAlias, that row is also
deleted
from tblAliasOriginal! Why? How can I prevent this?

Mar 14 '06 #2

This discussion thread is closed

Replies have been disabled for this discussion.