|
Okay, I have a better question.
How do you make a dataset persist between page refreshes without executing your query over and over?
Thanks.
SD
|
|
|
|
|
Simplest approach I'd have thought was to store the dataset in the Session:
private void Page_Load(object sender, System.EventArgs e)
{
// try to retreive an existing dataset from the Session
DataSet dataSet = (DataSet)Session.Contents["myDataset"];
// if there isn't one
if (dataSet == null)
{
// create it
dataSet = new DataSet();
// populate the dataset
// ...
// add it to the session, ready for retrievel next time
Session.Contents.Add("myDataset", dataSet);
}
// do stuff with the dataset here
}
Rob Philpott
|
|
|
|
|
Rob,
thank you for the response. This sounds like exactly what I want. However, I tried this and I keep running into a problem. First, I whipped up a simple dataset in the Global.ASAX file. Then, I debugged it on a page load.
When my page loads, the localDS is set to a new DataSet (per the code snippets below); however, line 103 executes and the localDS becomes <undefined value="">. So, what do you think is wrong with...
???localDS = (DataSet)Session.Contents["ds"];
Is there something special that is done in the declaration of ds in the GLOBAL file?
Thanks.
William
protected void Session_Start(Object sender, EventArgs e)
{
DataSet ds = new DataSet();
DataRow dr;
ds.Tables.Add("Test");
ds.Tables[0].Columns.Add();
ds.Tables[0].Columns[0].ColumnName = "Name";
ds.Tables[0].Columns.Add();
ds.Tables[0].Columns[1].ColumnName = "ID";
dr = ds.Tables[0].NewRow();
dr[0] = "Test1";
dr[1] = 1;
ds.Tables[0].Rows.Add(dr);
dr = ds.Tables[0].NewRow();
dr[0] = "Test2";
dr[1] = 2;
ds.Tables[0].Rows.Add(dr);
...
100 private void Page_Load(object sender, System.EventArgs e)
101 {
102 DataSet localDS = new DataSet();
103 localDS = (DataSet)Session.Contents["ds"];
...
|
|
|
|
|
Your code doesn't show where the newly created Dataset in Session_Start is added to the Contents dictionary (the Session.Contents.Add line in my original reply) - you may have left that bit out the code snippet - how are you doing this?
If the dataset isn't being added to the dictionary after its populated, we can't access it later, so that might be the problem.
Also, in line 102 it makes no sense to construct a new dataset, because in the next line localDS is either going to end up (hopefully) referencing the pre-created dataset or null if it can't find it, not the new DataSet you create on line 102.
Rob Philpott.
|
|
|
|
|
Rob,
first, let me really thank you for assisting so much. Problem solved because of your additional questions...
Your right, line 102 wasn't useful...I was just grabbing at straws.
The answer was, I did not realize that you had to add the dataset to the session dictionary with an "alias" name in order to access it: Session.Contents.Add("Myds", ds);
Thank you again...the code below works fine!
William
private void Page_Load(object sender, System.EventArgs e)
{
DataSet localDS = (DataSet)Session.Contents["Myds"];
dd1.DataSource = localDS;
dd1.DataTextField = "Name";
dd1.DataValueField = "ID";
dd1.DataBind();
...
protected void Session_Start(Object sender, EventArgs e)
{
DataSet ds = new DataSet();
DataRow dr;
ds.Tables.Add("Test");
ds.Tables[0].Columns.Add();
ds.Tables[0].Columns[0].ColumnName = "Name";
ds.Tables[0].Columns.Add();
ds.Tables[0].Columns[1].ColumnName = "ID";
dr = ds.Tables[0].NewRow();
dr[0] = "Test1";
dr[1] = 1;
ds.Tables[0].Rows.Add(dr);
dr = ds.Tables[0].NewRow();
dr[0] = "Test2";
dr[1] = 2;
ds.Tables[0].Rows.Add(dr);
Session.Contents.Add("Myds", ds);
...
|
|
|
|
|
No problem - glad to help
Rob Philpott
|
|
|
|
|
I have a set of XML files that I parse & put into a dropdown list. I don't want to read this set of files off the network every time the page loads.
I was considering establishing a data set in the GLOBAL.ASAX file in the Session section.
I would just bind that dataset on the page load for this one dropdown where it occurs in the application. NOW, I know I will hear some "purist" objections to using anything that sounds like a global variable, but it seems far more efficient than reading 100+ XML files every time the page loads for every user.
I have tried creating a dataset in the Session_Start, but it isn't clear how I would access it.
Any thoughts?
Also, I am curios if there is an equivalent to a variable declared on a page in VB "Public Shared MyInt As Integer"?
Thanks.
SD
|
|
|
|
|
I found the answer to my tranlation question. There is a nice site that does translations back and forth between VB & C#: http://www.carlosag.net/Tools/CodeTranslator/Default.aspx; however, I would still be interested in any response to my GLOBAL question.
Thanks again,
Sd
|
|
|
|
|
Forget it. This was a bad question. I simply put a public dataset on the page of interest and read the XML into the dataset on if (!PostBack).
Thanks anyway.
Sd
|
|
|
|
|
I've written a small C# assembly which does MX/ANAME lookups on a DNS server to get a list of mail servers/IP addresses for a particular domain, but I'm having some bother in programmatically finding out the IP address of the DNS servers to query. Currently I've hardcoded the IP of two BT DNS servers after looking them up on my DSL router.
Is there a way to find out the IP address(es) of the computer's DNS servers in .NET, and in particular in managed code without resorting to P/Invoke as I try to make my code work with Mono. I've trawled the net and had no luck in finding this out.
I would be most grateful to any genius who could show me the (a) way. Thank you!
Rob Philpott.
|
|
|
|
|
|
Thanks for the response leppie,
I could attempt something of the sort, but on Windows the DLL I'd need to talk to I believe also does MX and ANAME lookups too, making the whole project kind of redundant.
I really need a managed code solution, but I have doubts about whether one exists.
Rob Philpott
|
|
|
|
|
I need to validate text as nunber for 4 TextBoxes. Here is some code I wrote to validate the first TextBox, but this code locks me in the TextBox-- also
although it will handle an error the App won't close and again, I'm "frozen" in this text box. Thanks a lot.....
try
{
cmplxValue1.Real = Convert.ToDouble(textComplex_1Real.Text);
//cmplxValue1.Imaginary = Convert.ToDouble(textComplex_1Imaginary.Text);
}
catch(Exception ex)
{
error = true;
}
finally
{
if(error)
MessageBox.Show("Error");
textBox1.SelectAll();
textBox1.Focus();
e.Cancel = true;
}
}
|
|
|
|
|
|
|
I read RTFM and still don't get it.
e.Cancel = true; means nothing out of context
|
|
|
|
|
|
Wy not read the answers you got when you posted the question only 16 hours earlier, instead of posting it again?
---
b { font-weight: normal; }
|
|
|
|
|
While I am grateful for any response...I read them and they donn't work.
|
|
|
|
|
Well, if they don't work, say so. If you give no response at all to the ones that answer your question, but just post it again, it looks that you are completely ignoring the answers that you already got, giving no regard at all to the people trying to help you. Is that really the way you like to appear?
As you see, you will get the same answers all over again.
And did you really try the way that I suggested?
---
b { font-weight: normal; }
|
|
|
|
|
Guffa wrote: As you see, you will get the same answers all over again.
Tough day?
Regards
Senthil
_____________________________
My Blog | My Articles | WinMacro
|
|
|
|
|
Hello everybody here!!!.
i would like to know how can i add new command to the run process of the windows os for example .
press the following
--------------------
start ---> run --->and type ---->cmd or regedit
it will open the MsDos or Registry of the Windows OS respectively but i want to add new command like this of my own is it some string key or entry in the registry that manages this and by the way yahoo messenger do the same when you expose one friend's email from yahoo online member directory, you will see the online icon and you press that icon with this simple html script:
<br />
<a href="ymsgr:sendim?the_Friend_nickname">the online icon</a><br />
and it is it it opens for you private window for chatting with that friend.
I want to add command of my own like this any body has any solutions for this please refer to me with an idea or even an article on this.
As i guess ! it is all related to enter new key value data in the registry in specific part with the extension of your program , but where i don't know any body can help me in this please ..
Thanks From my heart
Mess With The Best And Die Like The Rest
|
|
|
|
|
Simple commands like cmd or regedit can be called because they are programs that can be found with the PATH environment variable. Start->Run also finds programs using the registry key "SOFTWARE\Microsoft\Windows\CurrentVersion\App Paths" if the program cannot be found using the PATH variable.
Registering new protocol like "ymsgr" is something different, but also quite easy: see http://msdn.microsoft.com/workshop/networking/pluggable/overview/appendix_a.asp[^]
|
|
|
|
|
You posted the exact same question in this exact forum less than 20 hours ago.
Why don't you follow up on the answers you get instead of spamming the forum with the same question again?
---
b { font-weight: normal; }
|
|
|
|
|
I want to know how can i make a wizard like a oledbconnection of Visual studio.net ,
exactly make something like the property Policy File of the component oledbconnection
|
|
|
|