|
if (txtdisc.Text == null)
{
..
Double txtdisc22013 = Convert.ToDouble(txtdisc.Text);
translates into
Double txtdisc22013 = Convert.ToDouble(null);
That does not make much sense.
|
|
|
|
|
It will never get that far as txtdisc.Text can never be null as it returns a string.
the OP should of tested it either by
if(string.IsNullorEmpty(txtdic.Text) != true)
{
}
or
if(txtdisc.Text != string.Empty)
{
}
Lobster Thermidor aux crevettes with a Mornay sauce, served in a Provençale manner with shallots and aubergines, garnished with truffle pate, brandy and a fried egg on top and Spam - Monty Python Spam Sketch
|
|
|
|
|
Hi
First, like others mentioned, "if" and "else" are conditional statements, they are not loop.
Second, the textbox will return empty if it has no value assigned to it, so checking for null is redundant.
Third, this is a coding horror!
if (txtdisc.Text ==null) This check is redundant therefore the calls below will never be executed.
{
txttot22013 = txtpr22013 + txtpr22014 + txtpr22015 + txtpr22016 + txtpr22017;
Double txtdisc22013 = Convert.ToDouble(txtdisc.Text); Converting a null to a nullable Double will 0.0;
txttot22013 = txttot22013 - txtdisc22013; (Some value – 0.0)
txttot.Text = txttot22013.ToString();
}
else
{
txttot22013 = txtpr22013 + txtpr22014 + txtpr22015 + txtpr22016 + txtpr22017;
txttot.Text = txttot22013.ToString(); The value of "txttot22013" in the else conditions is no different to the one in if condition.
}
if (txtvat.Text == null)
{
MessageBox.Show("Enter Vat Amount"); This will never be called.
}
else
{
Double txtvat22013 = Convert.ToDouble(txtvat.Text); Possible exception.
txtvat22013 = txtvat22013 / 100;
txtvat22013 = txtvat22013 * txttot22013;
Double txtvatinclu22013 = txtvat22013 + txttot22013;
txtvatinclu.Text = txtvatinclu22013.ToString();
}
If I rewrite your code, it may as follows:
txttot22013 = txtpr22013 + txtpr22014 + txtpr22015 + txtpr22016 + txtpr22017;
txttot.Text = txttot22013.ToString();
if (string.IsNullOrEmpty(txtvat.Text))
{
MessageBox.Show("Enter Vat Amount");
}
else
{
double txtvat22013;
if (Double.TryParse(txtvat.Text, txtvat22013))
{
Double txtvatinclu22013 = (txtvat22013 * txttot22013 / 100) + txttot22013;
txtvatinclu.Text = txtvatinclu22013.ToString();
}else
{
MessageBox.Show("Enter Valid Vat Amount");
}
}
Regards
Jegan
|
|
|
|
|
thanks a lot for suggestion but "loop" is my mistake i knw its a conditional statements ... thanks a lot for every one coz ur my seniors u have rights correct me....
|
|
|
|
|
Does that include correcting your English that you typed?
|
|
|
|
|
Hi All,
How to run the schedule task from .NET application?
Thanks in advance.
|
|
|
|
|
You're going to have to be a bit more specific than that. Since we're not sitting right next to you, we can't tell what your eyes were looking at and what your finger was pointing at when you said "How do I run that?"
Are you talking about Windows Task Scheduler? Some task in an application? Some task setup on a remote server?
|
|
|
|
|
Hi Dave,
I have an exe file which is placed in scheduler Tasks(Control Panel--->Scheduled Tasks). I need to have a dotnet program which should run this scheduler automatically from my program.
The above scheduled task is installed on my machine.
|
|
|
|
|
There's a bit of a problem. There are TWO Task Schedular APIs. I can't remember the exact deatils, but tasks created in one API cannot be seen in the other. So, if you app uses one API and you can't see the task you want, you'll have to rewrite against the other API.
|
|
|
|
|
Take a look at the Task Scheduler API: http://msdn.microsoft.com/en-us/library/aa383614.aspx
|
|
|
|
|
how to store images from imagelist\listview to spacific folder in c#
|
|
|
|
|
usually, something like
Bitmap b = new Bitmap(this.imageList1.Images[0]);
b.Save(@"Drive:\path\image-file-name.bmp");
"imageList1" obviously depends on what your Image List is called
|
|
|
|
|
how to store image from imagelist\listview to spacific fokder
|
|
|
|
|
|
As soon as you post an answer, the message that you posted against can't be deleted.
|
|
|
|
|
In my project we develop one application, which takes very long time for installation (many database interactions) & has many steps to follow.
Same for un-installation.
I want to automate this process, where the user will provide all the inputs at start & the installation will be done as per the instructions.
Example u have Visual studio 2012 setup. & u want to automate the installation, where u will provide all the inputs like languages, additional features & tools at the start of process. No need to wait in front of the machine.
I already have setup/installer.
I just want to automate the installation process ...
Whether is it 100% achievable by C# .NET?
If Yes then Please tell me how to start with? Plz share your experience if u have already done some thing like that before !!!
THANKS in Advance
~Rahul
|
|
|
|
|
Also the setup exe is a Java tool
|
|
|
|
|
Hi
Yes, you can automate the setup.
You can use tools like Autoit. But if you want to be more clever, use the inno setup to create you installer file. In the inno setup script you can define what to do during every stage of the installation.
Regards
Jegan
|
|
|
|
|
At my same company, we are using sql server 2008 r2 and C# 2010 and 2008 web, desktop and console applications that are accessing the same tables. Alot of time the tables are being accessed at the same time.
Thus my question is when do you recommend setting up connection pooling to the database. In other words, limiting the number of connections that can be setup to the database? I want to prevent too many deadlocks from occuring.
Thus can you tell me how the following:
1. when do you recommend connection pooling be setup?
2. Does it make a difference if this connection pooling is a web, desktop, console or some other C# application?
3. Can you point me to a reference and or some me some code how to setup the connection pooling?
|
|
|
|
|
classy_dog wrote:
1. when do you recommend connection pooling be setup? You don't have to do anything special to setup connection pooling. It is enabled and handled by framework automatically. But to make use of it fully, you need to dispose the SqlConnection objects immediately after using it. Obvious way to do this is to wrap connection objects in a using statement so that Dispose() gets called automatically. This is very important for the connection pool to perform well. Disposed objects goes back to the pool. When you do new SqlConnection() , it serves from the pool if available.
classy_dog wrote:
2. Does it make a difference if this connection pooling is a web, desktop, console or some other C# application? I don't think so. Connection pools lives in the "app domain". So for web applications, IIS manages this app domain and pools will be available throughout IIS lifecyle.
classy_dog wrote:
3. Can you point me to a reference and or some me some code how to setup the connection pooling? As I said earlier, you don't have to do anything. Just manage the connection objects properly.
Best wishes,
Navaneeth
|
|
|
|
|
My understanding is that the connection is returned to the pool when you close it; you don't need to dispose it immediately. I keep a connection for the life of am application (some of which are Services that run 24/7 for months on end) and open/close as needed.
I don't dispose (Usually with via using) until the application is ready to exit.
Instantiating the same connections millions of times a day is not a good idea.
IDbConnection.Close Method -- The Close method rolls back any pending transactions. It then releases the connection to the connection pool, or closes the connection if connection pooling is disabled.
http://msdn.microsoft.com/en-us/library/system.data.idbconnection.close.aspx[^]
|
|
|
|
|
PIEBALDconsult wrote: My understanding is that the connection is returned to the pool when you close it; you don't need to dispose it immediately.
From the documentation for SqlConnection.close()
"Close and Dispose are functionally equivalent."
PIEBALDconsult wrote: I keep a connection for the life of am application (some of which are Services that run 24/7 for months on end) and open/close as needed.
Not sure what that means. But
1. You should close it or dispose it when you are done with it in the functional block. There is no point in holding on to the instance.
2. The fact that a service is 24x7 doesn't mean that the database won't need to be rebooted. And if you are actually holding on to the connection then the result will be an exception. At least with the pool (connection close/disposed immediately) you have the chance of recovering eventually. The pool doesn't recover connections in use and it only drops connections when a usage attempt results in an error that is the result of a failed connection.
PIEBALDconsult wrote: Instantiating the same connections millions of times a day is not a good idea.
Object instantiation is a trivial cost in modern OO languages. So that can't be what you are referring to.
Connection creation in a modern data center is rather insignificant. However that doesn't matter because unless you explicitly set up the connection pool to do otherwise the pool will be holding active connections. So opening a connection does nothing but retrieve it from the pool. So "instantiating" means nothing in this context.
|
|
|
|
|
jschell wrote: "Close and Dispose are functionally equivalent
That's easy to disprove. Dispose also clears the ConnectionString so it needs to be set again if you want to reuse the instance (which you shouldn't from a purely ivory tower point of view).
jschell wrote: You should close it or dispose it when you are done with it in the functional
block
I close it.
jschell wrote: is rather insignificant
So? I'll still avoid it when I can.
modified 10-Feb-13 23:51pm.
|
|
|
|
|
classy_dog wrote: 1. when do you recommend connection pooling be setup?
Unless you have explicitly changed the connection configuration in your connection url then pooling always exists in C#/.Net.
classy_dog wrote: 2. Does it make a difference if this connection pooling is a web, desktop, console or some other C# application?
They behavior of the application makes a difference. For example generally it is pointless to have a pool in a standalone client application. And if one expects a lot of stand alone client applications then it could actually be a detriment. For low volume servers pools provide no benefit.
For high volume servers a pool might increase the overall tps (transactions per second). Whether that increase is significant is another matter. It depends on actual usage. However it will often have some positive impact.
There is a downside to pooling in that you must understand the limitations as well as understand how it behaves. For example if you have 100 active connections in the pool and the database is bounced, then you have 100 stale connections. Consequently those will result in 100 exceptions when you attempt to use them because the pool does not test them before giving them to you. And there is a very good reason for not testing them because doing so would basically incur the same cost as creating the connection in the first place as well as not providing any surety that when you use the connection that it still wouldn't be stale (because the database might be bounced after the test and before use.)
classy_dog wrote: 3. Can you point me to a reference and or some me some code how to setup the connection pooling?
As noted the connection pool is already set up.
If you wish to tune it for your application(s) then you can modify the url. That is documented in the following.
http://msdn.microsoft.com/en-us/library/system.data.sqlclient.sqlconnection.connectionstring.aspx[^]
Keep in mind that you can have different urls to the same database. Each connection string represents a different pool.
If you want to attempt to deal with the stale pool problem then look to the SqlConnection.SqlConnection.ClearAllPools() method.
|
|
|
|
|
When a user clicks a mailto link outlook may open, when a user clicks callto skype may open. How can I subscribe to these "events" in my own apllication.
what I want to do is open a custom app from a callto link on a webpage which will then in turn dial out using TAPI.
The problem I have is subscribing to this event.
|
|
|
|