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!

Automatic dataset = session in page_upload 1

Status
Not open for further replies.

warrendlr

IS-IT--Management
May 28, 2002
7
0
0
GB
Hello everyone,

In the page_load section of my aspx.vb, when reloading the page (postback), I have to retrieve the datasets using a (long) list of assignments
[tt]
Set dsMyDataSet1 = session("dsMyDataSet1")
Set dsMyDataSet2 = session("dsMyDataSet2")
Set dsMyDataSet3 = session("dsMyDataSet3")
...
[/tt]
(followed with similar instructions with dataviews)

I have already been able to replace the "daDataAdapter1.Fill(dsMyDataSet1)" list with a loop in the "if Not IsPostBack" subsection of Page_Load, and similarly to loop the saving of these datasets and dataviews in the session object.

I (somehow) store the datasets in a hashtable and then execute something like this in the Page_PreRender:
[tt]
Dim dsTemp as DataSet
For Each sTemp as String In htHashTable.Keys
dsTemp = htHashTable.Item(sTemp)
session(dstemp.DataSetName) = dsTemp
next
[/tt]

I am now trying to do the converse, i.e. to set the (existing) dataset objects back to the values stored in the session. Naturally, these datasets are used elsewhere than just in the page_load sub.

Of course, changing the above code [tt]session(dstemp.DataSetName) = dsTemp[/tt] with [tt]dsTemp=session(dstemp.DataSetName)[/tt] cannot work.

Does anyone have an idea on how to automatize these [tt]dataset=session("...")[/tt] lines ?

Thanks,

Warren
 
you can try to use System.Reflection to do this.

for example you can try
Code:
using System.Reflection;
...
...

// in your page load add
FieldInfo[] fi = (typeof([b]WebForm1[/b])).GetFields(BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.Public);

foreach (FieldInfo fInfo in fi)
{
     if (fInfo.GetType() == typeof(DataSet))
     {
          Object tmpDataSet = Session[fInfo.Name];
          if (tmpDataSet != null && tmpDataSet.GetType() == typeof(DataSet))
                fInfo.SetValue(this, (DataSet)tmpDataSet);
     }
}

i've not tested it but it should work!

--------------------------
"two wrongs don't make a right, but three lefts do" - the unknown sage
 
DaZZ: don't have time at the moment to test your solution but will do so in next day or so; an interesting approach. Nice contribution.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top