|
My C# WinForms 1.1 application uses same datareader query a lot of times and it is allowed that it can use cached result from previous datareader creation.
How to cache result obtained by datareader in memory so that in next time
cached query result is returned instead of making trip to server?
Or is it better to use DataTable and cache DataTable in memory?
Andrus
|
|
|
|
|
A DataReader only reads the data from the database, it doesn't contain the data. So if you want to persist the data, a DataSet or a DataTable would be what you would use.
---
Year happy = new Year(2007);
|
|
|
|
|
Datareader is always connected, better go for datatable to persist stuff!
|
|
|
|
|
be more explicit, and tell my if you need still this answer yet
regards
|
|
|
|
|
I found issue in .NET 2 where MenuStrip is not removed from MDI child window.
How to fix this ?
Andrus.
To reproduce:
1. Run the code
2. Select File / open
Observed: child window contains MenuStrip with File menu item.
Expected: child window should not contain MenuStrip
Code to reproduce the issue:
---- program.cs:
using System.Windows.Forms;
using WindowsApplication1;
static class Program {
static void Main() {
Application.Run(new Form1());
}
}
--- form1.cs
using System.Windows.Forms;
using System;
namespace WindowsApplication1 {
public partial class Form1 : Form {
public Form1() {
InitializeComponent();
}
private void openToolStripMenuItem_Click(object sender, EventArgs e) {
Form2 newMDIChild = new Form2();
newMDIChild.MdiParent = this;
newMDIChild.Show();
}
}
}
----- form1.designer.cs
namespace WindowsApplication1 {
partial class Form1 {
private System.ComponentModel.IContainer components = null;
protected override void Dispose(bool disposing) {
if (disposing && (components != null)) {
components.Dispose();
}
base.Dispose(disposing);
}
#region Windows Form Designer generated code
private void InitializeComponent() {
this.menuStrip1 = new System.Windows.Forms.MenuStrip();
this.fileToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.openToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.menuStrip1.SuspendLayout();
this.SuspendLayout();
this.menuStrip1.Items.AddRange(new System.Windows.Forms.ToolStripItem[] {
this.fileToolStripMenuItem});
this.menuStrip1.Location = new System.Drawing.Point(0, 0);
this.menuStrip1.Name = "menuStrip1";
this.menuStrip1.Size = new System.Drawing.Size(292, 24);
this.menuStrip1.TabIndex = 1;
this.menuStrip1.Text = "menuStrip1";
//
// fileToolStripMenuItem
//
this.fileToolStripMenuItem.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] {
this.openToolStripMenuItem});
this.fileToolStripMenuItem.Name = "fileToolStripMenuItem";
this.fileToolStripMenuItem.Size = new System.Drawing.Size(35, 20);
this.fileToolStripMenuItem.Text = "&File";
//
// openToolStripMenuItem
//
this.openToolStripMenuItem.Name = "openToolStripMenuItem";
this.openToolStripMenuItem.Size = new System.Drawing.Size(152, 22);
this.openToolStripMenuItem.Text = "&open";
this.openToolStripMenuItem.Click += new System.EventHandler(this.openToolStripMenuItem_Click);
//
// Form1
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(292, 273);
this.Controls.Add(this.menuStrip1);
this.IsMdiContainer = true;
this.MainMenuStrip = this.menuStrip1;
this.Name = "Form1";
this.Text = "Form1";
this.menuStrip1.ResumeLayout(false);
this.menuStrip1.PerformLayout();
this.ResumeLayout(false);
this.PerformLayout();
}
#endregion
private System.Windows.Forms.MenuStrip menuStrip1;
private System.Windows.Forms.ToolStripMenuItem fileToolStripMenuItem;
private System.Windows.Forms.ToolStripMenuItem openToolStripMenuItem;
}
}
-------- form2.designer.cs
namespace WindowsApplication1 {
partial class Form2 {
private System.ComponentModel.IContainer components = null;
protected override void Dispose(bool disposing) {
if (disposing && (components != null)) {
components.Dispose();
}
base.Dispose(disposing);
}
#region Windows Form Designer generated code
private void InitializeComponent() {
this.menuStrip1 = new System.Windows.Forms.MenuStrip();
this.fileToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.saveToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.menuStrip1.SuspendLayout();
this.SuspendLayout();
//
// menuStrip1
//
this.menuStrip1.Items.AddRange(new System.Windows.Forms.ToolStripItem[] {
this.fileToolStripMenuItem});
this.menuStrip1.Location = new System.Drawing.Point(0, 0);
this.menuStrip1.Name = "menuStrip1";
this.menuStrip1.Size = new System.Drawing.Size(292, 24);
this.menuStrip1.TabIndex = 0;
this.menuStrip1.Text = "menuStrip1";
//
// fileToolStripMenuItem
//
this.fileToolStripMenuItem.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] {
this.saveToolStripMenuItem});
this.fileToolStripMenuItem.MergeAction = System.Windows.Forms.MergeAction.MatchOnly;
this.fileToolStripMenuItem.Name = "fileToolStripMenuItem";
this.fileToolStripMenuItem.Size = new System.Drawing.Size(35, 20);
this.fileToolStripMenuItem.Text = "&File";
//
// saveToolStripMenuItem
//
this.saveToolStripMenuItem.MergeAction = System.Windows.Forms.MergeAction.Insert;
this.saveToolStripMenuItem.MergeIndex = 3;
this.saveToolStripMenuItem.Name = "saveToolStripMenuItem";
this.saveToolStripMenuItem.Size = new System.Drawing.Size(152, 22);
this.saveToolStripMenuItem.Text = "Save";
//
// Form2
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(292, 273);
this.Controls.Add(this.menuStrip1);
this.MainMenuStrip = this.menuStrip1;
this.Name = "Form2";
this.Text = "Form2";
this.menuStrip1.ResumeLayout(false);
this.menuStrip1.PerformLayout();
this.ResumeLayout(false);
this.PerformLayout();
}
#endregion
private System.Windows.Forms.MenuStrip menuStrip1;
private System.Windows.Forms.ToolStripMenuItem fileToolStripMenuItem;
private System.Windows.Forms.ToolStripMenuItem saveToolStripMenuItem;
}
}
-------- form2.cs
using System.Windows.Forms;
namespace WindowsApplication1 {
public partial class Form2 : Form {
public Form2() {
InitializeComponent();
}
}
}
Andrus
|
|
|
|
|
If so, is it bad form to do this? The idea is that I have one process running in the background and my webpage being updated by what's stored in the session variable.
I know there's got to be a best practise way to do this. I just can't find much on it. My idea was to use what's stored in the session variable, refesh the page every 5 seconds and poll the session state. Any one?
|
|
|
|
|
Why don't you use AJAX to send a message back to your page when the thread is done, instead of updating every 5 seconds ?
Christian Graus - C++ MVP
'Why don't we jump on a fad that hasn't already been widely discredited ?' - Dilbert
|
|
|
|
|
Well, I want to update more than just when the threead is done.
|
|
|
|
|
I'm not sure what you mean ? Once you know the thread is done, you can send the data through AJAX, or prompt the page to refresh itself, now that there's a reason to.
Christian Graus - C++ MVP
'Why don't we jump on a fad that hasn't already been widely discredited ?' - Dilbert
|
|
|
|
|
I think that there is something about AJAX that you have missed. You can do a lot of things with it, but server push is not one of them. It still uses the http protocol, where there is no way for the server to send data to the browser without the browser first requesting it.
---
Year happy = new Year(2007);
|
|
|
|
|
I know how AJAX works. If his page knows it needs to refresh itself ( as it does ), then it could be written so the page sends an AJAX request, asking for the process to occur ( whatever it is ), and the response can be sent when the process is finished. Obviously, the page needs to be written to know about the process, and the request needs to be written so it can be requested by an AJAX call.
Christian Graus - Microsoft MVP - C++
Metal Musings - Rex and my new metal blog
|
|
|
|
|
Ok. It just sounded from your previous posts as though you thought that you could send messages from the server to the browser using AJAX.
---
Year happy = new Year(2007);
|
|
|
|
|
The web server only assures that the session object is valid while the thread responding to the request is running. If you hold on to the object after that thread has ended, there is no guarantee that it's still valid.
Use the Application object instead, or a static variable. But you have to use some kind of identifier to separate data for different threads.
---
Year happy = new Year(2007);
|
|
|
|
|
I am ,lets say, newcomer from MFC to C#.
With MFC using SDI model, I can switch from one view to another like follow
BOOL CMainFrame::ReplaceView(CRuntimeClass * pNewViewClass)
{
CView* pOldActiveView = GetActiveView();
CCreateContext context;
context.m_pNewViewClass = pNewViewClass;
context.m_pCurrentDoc = GetActiveDocument();
CView* pNewView = STATIC_DOWNCAST(CView,CreateView(&context));
if (pNewView != NULL)
{
pNewView->ShowWindow (SW_SHOW);
pNewView->OnInitialUpdate();
SetActiveView(pNewView);
pOldActiveView->ShowWindow (SW_HIDE);
// DestroyWindow calls PostNcDestroy which then deletes the
// pOldActiveView object.
pOldActiveView->DestroyWindow();
RecalcLayout();
}
return TRUE;
}
Questions :
1. Can I do similiar things to switch my forms ?
2. Or can you suggest another approach ?
3. And please sample project?
Thanks
|
|
|
|
|
Learning things is always good. Learning new approaches is always perfect
Taking into account that actually you are new to the new technologies, it is, perhaps, better for you start with latest staff. Therefore, I encourage you to have a "look" at Windows Presentation Foundation, which is the new strategic graphics subsystem in Windows that provides a unified approach to user interface, 2D and 3D graphics, documents and media.
You can take a tour here[^].
-- modified at 5:40 Monday 8th January, 2007
SkyWalker
|
|
|
|
|
How to do this.
In textBox must be inserted only decimal numbers.
When i insert something else like characters to fire an event.
Vasildb
|
|
|
|
|
Handle the KeyPress , KeyDown or KeyUp events depending on when you want it to occur. Alternatively you could handle the Validating event.
I have no idea what I just said. But my intentions were sincere.
|
|
|
|
|
... And when you use the KeyPress event, you can get the character from the KeyPressEventArgs which with a default event handler is named e. That object has a property named KeyChar that contains the Char that was typed. Therefore, this code should prevent non-decimal data entry.
private void KeyPressed(Object o, KeyPressEventArgs e)<br />
{<br />
e.Handled = (!char.IsDigit(e.KeyChar));<br />
}
|
|
|
|
|
<br />
decimal x = 0;<br />
try<br />
{<br />
x = decimal.parse(TextBox1.Text);<br />
}<br />
catch<br />
{<br />
MessageBox.Show("Please Enter Decimal Numbers");<br />
}
|
|
|
|
|
Hello,
At the .Net Frameworks > 1.1, decimal.TryParse would be possible, or in 1.1 the double class has a TryParse method.
So there would be no need of a try/catch!
All the best,
Martin
|
|
|
|
|
How to do that with TryParse .
Message:
No overload for method 'Try Parse' takes '1' arguments
Help.
Vasildb
|
|
|
|
|
Hello Vasildb,
using System.Globalization;
decimal actvalue;
if(decimal.TryParse("534",NumberStyles.Number, CultureInfo.CurrentCulture, actvalue) == true)
{
}
else
{
}
All the best,
Martin
|
|
|
|
|
|
What experience do you have with O/R mapper in .NET?
I need to choose one for use in my company
Which one is the best for you?
I have seen lots of positive feedback about this one:
LLBLGen Pro
What do you thing about this? Is it good or can I find better alternative?
Regards
cyberjoe
|
|
|
|
|
You can also look into NHibernate[^]. There are quite a few codegenerators out there that make setting up a basic solution with NHibernate a breeze
WM.
What about weapons of mass-construction?
"You can always try to smash it with a wrench to fix that. It might actually work" - WillemM
|
|
|
|