|
|
ImranTech,
Just use AppConfig.
Regards,
Gareth.
|
|
|
|
|
hello frnds,
i have a windows application developed in C#.Net 2.0, i want to transafer a textbox value to anoter form Text how can i do that.
let consider i have frmOne having a textbox txtOne, a button OK, and another form frmTwo
i want to set the value of textbox as a text of frmTwo when i click button Ok
my code is here
//Click event of OK button
frmTwo frtwo = new frmTwo()
frtwo.text = txtOne.text
frtwo.show()
but faliled..
where i am wrong???
please help ????
thankx in advance
-koolprasad2003
Be a good listener...Because Opprtunity knoughts softly...N-Joy
|
|
|
|
|
Overload form2's constructor which accepts a string value as parameter. Pass the first textbox value to this when you are invoking form2.
frmTwo frtwo = new frmTwo(txtOne.text)
frtwo.show() Inside for2 constructor, assign the value to respective text box.
|
|
|
|
|
|
Please don't do this. If you want to be a better developer, you should learn about design patterns and how they help you design software. You can solve this issue using either the Observable pattern or the Model View Controller/Model View Presenter patterns. Please look at using them.
BTW - it's not Opportunity knoughts softly, it's Opportunity knocks softly.
|
|
|
|
|
I am not getting how it can help in passing one value other form ?
|
|
|
|
|
N a v a n e e t h wrote: I am not getting how it can help in passing one value other form
Because you don't pass values from one form to another. You create a data model and put views on the model. These views get updated when things change. It's that simple.
Suppose you want to extend this issue and have the same value updated in 20 or 30 places, using a pattern makes this trivial. Using hard coded value passing makes it complicated.
|
|
|
|
|
That's great. Thanks. Do you have any good links for MVC implementation on C# ?
|
|
|
|
|
This[^] is a good source of information. This[^] is also excellent - it's very deep and takes a lot of reading, but stick with it.
|
|
|
|
|
Thanks. I will take a look
|
|
|
|
|
I need to pass the IP address to app.config file that is created after installing the project.I got to add the web reference to run my service.
Web reference would be ..
http://202.79.41.240/Setup12/Service.asmx.
Now I need to change the IP address that gets stored in app.config file.
Thanx in advance.
|
|
|
|
|
XmlDocument xDoc = new XmlDocument();<br />
xDoc.Load(@"YOURPATH\App.config");<br />
if (xDoc.DocumentElement.SelectSingleNode("appSettings/add").Attributes.GetNamedItem("key").InnerText == "IP")<br />
{<br />
xDoc.DocumentElement.SelectSingleNode("appSettings/add").Attributes.GetNamedItem("value").InnerText = "genericIP";<br />
xDoc.Save(@"YOURPATH\App.config");<br />
}
But I am not sure how safe it is to handle you app config file in dynamically
Sathy
|
|
|
|
|
Hii All
Could any one please tell me how to insert multiple rows in a single column with single insert statement. I am using MySql Database with C#. Actually i want a structure something like this
JobNum NatureOfComplaint
J001 Changing Tyres
Repairing Engine
Repairing Side Bumper
J002 Changing Engine
Repairing Engine
Touch Painting
I have two columns named JobNum and NatureOfComplaint now i want to
insert one Job Number for example J001 and more than one Nature of complaint under J001 itself as shown above.
How it can be done with C# and MYSQL.
My ultimate goal is i have to create several textboxes at runtime when ever a user clicks of more button one text box should get added and thereafter i want to insert the values from those text boxes to the database.
Any help will be appreciated
Thanks.
Imran
|
|
|
|
|
You can form a single string with some delimiters and insert to the table. But this looks a bad design. You could create two table's where JobNum would be the primary key in the first table and foreign key to the second table. In second table you need to add each row for each NatureOfComplaint .
|
|
|
|
|
The code which i have currently written to insert the values is
try
{
string strInsert = "insert into Quotation" +
"(JobNum, NatureOfComplaint1, NatureOfComplaint2, NatureOfComplaint3)"
+ "values('" + this.txtNatureofComplaint1.Text + "','" + this.txtNatureofComplaint2.Text + "','" + this.txtNatureofComplaint3.Text + "')";
{
MySqlCommand command = new MySqlCommand(strInsert, Quotation.con);
Quotation.dQuotationAdapter.InsertCommand = command;
//Insert new record
Quotation.dQuotationAdapter.InsertCommand.ExecuteNonQuery();
MessageBox.Show("New Record Saved Successfully");
}
catch (MySqlException ex)
{
MessageBox.Show(ex.ToString());
}
catch (Exception ex)
{
MessageBox.Show(ex.ToString());
}
}
In the above code i want to insert one value for JobNum and three values for NatureofComlpaint from different text boxes. So if there are three textboxes from where i want to fetch the value and store it into a single column of NatureofComplaint then how i will do that.
It always throws an exception that value count dosent match the row count.
How can i slove this issue.
Imran
|
|
|
|
|
Hi,
Recently I have launched a service and it is working fine.
The problem now is it lapses a second for every 2 days.
Is there any workaround to solve this.
Can any one advise me on this.
Long Live
|
|
|
|
|
What do you mean? What lapses a second? What processing is going on? Without this information, I wouldn't even begin to know where to look.
|
|
|
|
|
Hi thanks for you reply.
The service generates a file on a daily basis at a specified time range mentioned in the app config file. For this purpose the service will make a check the current time against the one in config file for every 5 mins.
This part works fine. The problem is for example if it check by 12:34:33 pm the next check is performed exactly at 12:39:33 PM.
But in course of time say a day or two the checking drifts from 12:34:33 PM to 12:34:34 PM. Like this with in a month the polling time chages to 12:35:XX PM.
I wish to put a check on this. B'coz if the file generation time range is between 12:33:00 PM 12:36:00 PM in course of time the service may run without generating the file.
Thanx and Rgds,
Long Live
|
|
|
|
|
Without looking at the code, how do you expect us to help you?
*If* you are using Thread.Sleep(5 * 1000), then it will not be correct because the actual processing work takes up some time. Use a Timer instead.
Cheers,
Vikram.
"If a trend is truly global, then that trend ought to be visible across ANY subset of that data" - fat_boy
|
|
|
|
|
I suspect that what you are seeing is simply the result of an operation taking time to complete, and the timer that is doing the polling is gradually slipping as a result.
|
|
|
|
|
This is how i coded.
lDueTime = 60000;
lPeriod = 300000;
TimerCallback timerDelegate = new TimerCallback(FileOperations);
ThreadTimer = new Timer(timerDelegate, null, lDueTime, lPeriod);
public void FileOperations()
{
// My code goes here
}
Long Live
|
|
|
|
|
Hi,
in my program, I want to prepare a choice for user to make the program run when windows starts. (But not when s/he installs the program) I want to make it optional. For that I wrote (when the user checks that option):
string registryaddress = @"Software\Microsoft\Windows\CurrentVersion\Run";
RegistryKey rk = Registry.CurrentUser.OpenSubKey(registryaddress).CreateSubKey("programname");
rk.SetValue("programname",Application.ExecutablePath);
and I get a runtime error as follows :
"Unauthorized access exception " , Cannot write to the registry key...
I need help in this one, and also when the user unchecks this option , I have to delete this registry right?
But the bigger problem occurs when user checks this option but uninstalls the program after that. How can I make the C# Setup Deployement project (I mean the installer) uninstall this registry file, which had not been installed during the installation rather done by the user sometime after.
Thanks..
|
|
|
|
|
Registry.CurrentUser.OpenSubKey(registryaddress)
opens the key as a readonly key. Try
Registry.CurrentUser.OpenSubKey(registryaddress, true)
to open it with write permissions. MSDN[^]
To have the installer remove it on an un-installation, you could have the installer put the key in the registry when the program is installed; then when the installer is run to remove the program it'll automatically remove the key for you. If you want the autostart disabled by default then you could put a little check in your app that removes the key the first time it's run. It may be a little kludgy but it's just an idea
|
|
|
|
|
ok, but when I open the registry part in the setup project, tree-view on the left shows registry but narrows down only to :
H_KEY_CURRENT_USER -> Software -> [Manufacturer]
while I somehow must create the key in the following path, as we talked about earlier :
H_KEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Run
I'm not familiar with registry stuff so I'm stuck at this point
On the other hand, some friends said I could put a shortcut to my application's exe file into the Users Startup Folder using Setup Project.
This method seems to be working but to avoid the autostart, I shall delete this shortcut when user doesn't want so. This brings me two other problems as:
1) Startup path is
C:\Documents and Settings\[username]\Start Menu\Programs\Startup
but how can I get the username?
2) I dont even know how to make a shortcut. I only know File.Rename, File.Exists and File.Delete
I would be too glad if you help me out in either scenarios.
|
|
|
|