Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Assinging an object to a variable...

Status
Not open for further replies.

warrendlr

IS-IT--Management
May 28, 2002
7
0
0
GB
Hi. I would like to do the following:

I enumerate all my datasets in a collection (say in a hashtable htHashTable).

Now, I would like to use something like
dsMyDataSet = session("dsMyDataSet")
where the session variable has been set previously, but where I could use a "for each" instruction to loop among the items of my collection. I would be something like

Dim dsTemp as DataSet
For Each sTemp as String In htHashTable.Keys
dsTemp = htHashTable.Item(sTemp)
dsTemp = session(dstemp.DataSetName)
next

Of course, this does not work, as the variable dsTemp is never used as a pointer to the real dataset dsMyDataSet, and thus the assignment of the session object is not done to the dsMyDataSet object.

Does anyone have an idea on how to proceed ?
 
To set a variable to an object you must use the Set command (though I don't think it's going to work for you, either), like:
Code:
Set dsMyDataSet = session("dsMyDataSet")
 
Hello warrendlr,

It is not clear the platform where your code is destined to. But, if you declare dsTemp in late-binding as variant, this is how it might be working if session(...) is storing a simple variant.
[tt]
Dim dsTemp, x 'x being an intermediate place holder
For Each sTemp In htHashTable.Keys
set dsTemp = htHashTable.Item(sTemp)
x=dsTemp.DataSetName
set dsTemp = nothing
dsTemp = session(x) 'if session(x) is a simple variant
next
[/tt]
But then, you can simple do thing like if what session(...) stored is a dataset object.
[tt]
Dim dsTemp As DataSet
For Each sTemp in htHashTable.Keys
Set dsTemp = session(htHashTable.Item(sTemp).DataSetName)
Next
[/tt]
But having dsTemp unchanged with a for-next loop lead us all wondering.

regards - tsuji
 
Hi. Thanks Genimuse and tsuji for the answers.

Actually, I am trying to replace a (long) list of assignments
Set dsMyDataSet1 = session("dsMyDataSet1")
Set dsMyDataSet2 = session("dsMyDataSet2")
Set dsMyDataSet3 = session("dsMyDataSet3")
...
(followed with similar instructions with dataviews)
in the "Page_Load" section of an ASP.Net page by something more "automatized".

I could replace the "daDataAdapter1.Fill(dsMyDataSet1)" list with such a loop in the "if Not IsPostBack" subsection of Page_Load, and similarly to loop the save of these datasets and dataviews in the session object.

I am now trying to do the converse, i.e. to set the (existing) dataset objects back to the values stored in the session. Of course, the datasets are then used elsewhere in the aspx.vb file... I cannot just work with the local dsTemp...

Any idea ?
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top