|
Probably create a separate class to hold the values or perhaps use a Dictionary to store them.
Basically, as I told you yesterday[^].
|
|
|
|
|
yup...
I knw about yesterday but I just wanted to know how to create it at run time instead of creating at design time..
|
|
|
|
|
Without resorting to codeDOM and dynamically generating code or an assembly, there is no way to create a variable or property at runtime.
You could use a hashtable.
I know the language. I've read a book. - _Madmatt
|
|
|
|
|
well, i was thinking of an sql table with the following fields:
system_param_id int (PrimaryKey)
system_param_name varchar(50)
system_param_value varchar(50)
and when logging to the system then it will populate each record with two things:
param_name
param_value
so if I have 100 records in that table then I will have 100 variables..
what's the best method to use?
|
|
|
|
|
Why a database? Would these variables need to be saved from session to session? Where do they come from in the first place. A simple Hashtable stored in a static variable may be all that's necessary.
I know the language. I've read a book. - _Madmatt
|
|
|
|
|
Well Im completly agree with PIEBALDconsult.
Use either dictionary or hashtable object to store all parameters as key, value pair.
This will be much easier to maintain as well as you have only one public variable.
|
|
|
|
|
how can I have the hashtable as public? I tried the following but not working!
my public class is:
using System;
using System.Collections;
using System.Collections.Generic;
using System.Text;
namespace cure_hospital_management
{
class public_class
{
private Hashtable _sysem_parameters;
public Hashtable sysem_parameters
{
get { return _sysem_parameters; }
set { _sysem_parameters = value; }
}
}
}
my code in the mail form load is:
<pre>public_class public_var = new public_class();
private void get_system_parameters2()
{
public_var.sysem_parameters = new Hashtable();
public_var.sysem_parameters.Add("Name", "Jassim Rahma");
}
</pre>
and my code to read the value is:
<pre>MessageBox.Show((string)public_var.sysem_parameters["Name"]);</pre>
but I am getting this error when reading the value:
Object reference not set to an instance of an object.
|
|
|
|
|
u need to call get_system_parameters2() before accessing hashtable.
First follow some guidlines to make it more perfect
1. Move sysem_parameters = new Hashtable(); in public_class class.
2. Check if hasttable is null then create new instance of hasttable in get part of sysem_parameters.
3. Have a look at Singleton pattern
|
|
|
|
|
how can I keep one sql connection alive in my application and use that connection in my all forms? and does it have any disadvantages?
|
|
|
|
|
Your application shouldn't know anything about the database.
Your application should have a business layer. You can pass a reference to the business layer to each form, then they can each use it.
|
|
|
|
|
so you mean i should open and close the connection in every form?
|
|
|
|
|
Yes, inside the Data Access Layer, the connection would be opened and closed for each operation.
And watch out for threading issues.
|
|
|
|
|
Usually, you open and close the connection on every operation. You don't keep a connection open for the life of a form or for an entire applications lifetime. SQL Server (or other) licenses are expensive and connections consume resources on both the client and server side. You grab a connection, use it, then release it when your operation is complete.
Again, you UI code should have nothing to do with the database connection at all. That is up to your business and data layers.
|
|
|
|
|
No it does not have an advantage, it could in fact be a severe disadvantage. If you are concerned about performance, then as PIEBALD has said, use a business layer that could potentially cache data.
I know the language. I've read a book. - _Madmatt
|
|
|
|
|
Keeping SQL connection alive is a bad idea. Usual pattern for using SQL connection is to open it, execute the SQL and close it. ADO.NET has connection pooling built in and creating a new instance of SQL connection can return from pooled objects.
What are you trying to achieve by keeping the connection alive?
Best wishes,
Navaneeth
|
|
|
|
|
How can I make a specific printer a default printer for my application regardless of the windows default printer so the user will always print to the application printer without making the user to choose which printer to print on?
|
|
|
|
|
You need to use the PrintDocument class in a manner similar to the following:
PrintDocument prndoc = new PrintDocument();
prndoc.DocumentName = "My document";
prndoc.PrintPage += new PrintPageEventHandler(PrnPage);
prndoc.PrinterSettings.PrinterName = strPreferredPrinter;
prndoc.PrinterSettings.DefaultPageSettings.Landscape = true;
prndoc.DefaultPageSettings.Landscape = true;
prndoc.Print();
Every time the program runs, it should check to see if the preferred printer is still available. This is done by something like this:
PrinterSettings ps = new PrinterSettings();
ps.PrinterName = strPreferredPrinter;
if (! ps.IsValid) {
ps = new PrinterSettings();
strPreferredPrinter = ps.PrinterName;
}
Hope this helps. Happy programming!
modified on Friday, April 9, 2010 2:16 PM
|
|
|
|
|
Hello,
I'm trying to make an application in C# that will connect to a web cam, show the video stream and then draw text over the video. I have search countless hours and found an example using directshow that put texts over video that is being played from a file, but not from a live video stream from a web cam. Does anyone know how this can be done with a web cam or know where I could find any examples?
|
|
|
|
|
i´m trying to make a web form to do auto -login in a web game but the login page don't have a click button but have a input type ="image"
Code from the web page:
<div style ="height:180px;padding-top:36px;" >
<form action ="index.php?ac=loginpage" method ="post" style ="margin:0px;padding:0px;" onsubmit ="esvtk_track( {esvtk_v:'1',
esvtk_esvid:'A10050' , event:'reg_monstersgame', amount:'1'});" >
<div >
<table width ="100%" style ="text-align:left;" >
<tr >
<td >
servidor:
</td >
<td >
<select name ="server" onchange ="javascript:location.href=this.value;" size ="1" class ="input" >
<option value ="http://www.monstersgame.com.pt/?ac=loginpage" > World 1</option >
<option value ="http://world2.monstersgame.com.pt/?ac=loginpage" > World 2</option >
<option value ="http://world3.monstersgame.com.pt/?ac=loginpage" > World 3</option >
<option value ="http://world4.monstersgame.com.pt/?ac=loginpage" > World 4</option >
<option value ="http://world5.monstersgame.com.pt/?ac=loginpage" > World 5</option >
<option value ="http://world6.monstersgame.com.pt/?ac=loginpage" > World 6</option>
<option value ="http://world7.monstersgame.com.pt/?ac=loginpage" > World 7</option >
<option value ="http://world8.monstersgame.com.pt/?ac=loginpage" > World 8</option >
<option value ="http://world9.monstersgame.com.pt/?ac=loginpage" > World 9</option >
<option value ="http://world10.monstersgame.com.pt/?ac=loginpage" selected ="selected" > World 10</option>
</select >
</td >
</tr >
<tr >
<td >
Nome:
</td >
<td > <input type ="text" name ="user" size ="30" style ="width:170px;" /> </td >
</tr >
<tr >
<td >
Senha:
</td >
<td > <input type ="password" name ="password" size ="30" style ="width:170px;" /> </td >
</tr >
<tr >
<td colspan ="2" style ="text-align:center;" >
<input type ="checkbox" name ="gfxpack" value ="1" style ="background:none;" /> Carregar imagens do servidor
<input type ="image" src ="img/teaser/EN/teaser_btn_verwandeln.jpg" alt ="Transformar" title ="Transformar" />
i can put the user name and the password but i can't send this information to the server
if some one could help me i will apreciate
|
|
|
|
|
Are you trying to submit the form while clicking image button?where you are validating username and password?
tedyboy9 wrote: onsubmit ="esvtk_track( {esvtk_v:'1',
esvtk_esvid:'A10050' , event:'reg_monstersgame', amount:'1'});"
what's this method actually do?Check if that method is suppressing the submit.
|
|
|
|
|
private void webBrowser1_DocumentCompleted(object sender, WebBrowserDocumentCompletedEventArgs e)
{
webBrowser1.Document.GetElementById("user").SetAttribute("value", textBox3.Text);
webBrowser1.Document.GetElementById("password").SetAttribute("value", textBox4.Text);
}
you see i can get this elements from the web page and i set his attributes , when i make login there are a image button in the web page , what i want is my web form make all this things to me
put username
put password
and click that image button for me to make the Auto-login
there is the link to the web game where i make login , you can see whow this works
http://world10.monstersgame.com.pt/[^]
thanks
|
|
|
|
|
Hey...
I need to implement 2 methods asynchronous methods, one for reading data, and one for writing...
the ManualResetEvent initialization is with false ManualResetEvent mre = new ManualResetEvent(false);
if i understand correct, it means that it'll be block the accessing thread till the set() will be executed.
what will happen if one thread will execute set(), and after it, other thread will execute WaitOne() before Reset was executed, it will be blocked, or the thread will continue running
I hope i was clear enough
Thanks
|
|
|
|
|
Hi,
the MSDN documentation on ManualResetEvent clearly states: "Once it has been signaled, ManualResetEvent remains signaled until it is manually reset. That is, calls to WaitOne return immediately."
|
|
|
|
|
If you are trying to effectively solve a producer/consumer problem, I would suggest looking into the Monitor class, particularly Monitor.Wait and Monitor.Pulse; in a typical producer/consumer situation, the consumer wants to check whether any data is available, and if not start waiting on an object without giving the producer a chance to add data and flag the object between the consumer's check and wait. While this sort of thing can be done with some WaitHandle objects, it's easier to use Monitor.Wait and Monitor.Pulse.
|
|
|
|
|
it's not a "producer/consumer problem"
and Monitor isn't good for me, it uses the object directly, and i don't have an access to it (private field in other class)
|
|
|
|