Hi,
How can I convert this code so that it accepts decimal values too.
int city = Convert.ToInt32(txtCities.Text);
Loading
Know the answer? Post it. Somebody with the same question will find it here.
Answer a question in the forums and earn +20 SHARP for every answer.
See unanswered questions
DevSocialUpcoming · 3rd editionAI Agents ConferenceDec 1–3, 2026Live onlineFree to attend5days leftRegister
VulpesRank #55 · 29.2K reputationPosted Oct 30, 2013, 4:17 AM EDT
decimal city = Convert.ToDecimal(txtCities.Text);
Sanjeeb LenkaRank #301 · 8.3K reputationPosted Oct 30, 2013, 4:20 AM EDT
decimal city = Convert.ToDecimal(txtCities.Text);
Vignesh KumarRank #1,579 · 1K reputationPosted Oct 30, 2013, 4:36 AM EDT
public void Update(string AppName, string critical, string Hrs)
{
SqlConnection conn = new SqlConnection(cnstr);
conn.Open();
SqlCommand cmd = new SqlCommand("sp_Sharepoint_rs_AppsInfra_Data_Utility", conn);
cmd.Parameters.Add("@mmyy", SqlDbType.VarChar, 200).Value = month.Text;
cmd.Parameters.Add("@appname", SqlDbType.VarChar,200).Value = AppName;
cmd.Parameters.Add("@critical", SqlDbType.Int).Value = critical;
cmd.Parameters.Add("@Hrs", SqlDbType.VarChar,10).Value = Hrs;
cmd.Parameters.Add("@id", SqlDbType.Int).Value = 1;
cmd.CommandType = CommandType.StoredProcedure;
cmd.ExecuteNonQuery();
conn.Close();
conn.Dispose();
}
@critical and @hrs are the two text box where I enter decimal values.
Failed to convert parameter value from a String to Int32
VulpesRank #55 · 29.2K reputationPosted Oct 30, 2013, 4:46 AM EDT
It appears that 'critical' is of type int and so you're not going to be able to use decimal for that.
However, 'hrs' is of type varchar and so you could pass a decimal string to that.
Sammi Sharief2 reputationPosted Oct 30, 2013, 10:58 AM EDT
Can you help me with this questions?
1. Develop a console programme that reads an integer n and a list of up to 5 divisors (also integers) from the console and computes the sum of all integers up to (but excluding) n which are divisible by any of the five divisors. For example if n = 10, and the list of divisors provided is [3, 5] then the numbers divisible by 3 or 5 are 3, 5, 6, 9 and their sum is 23 and hence the output is 23.
Provide a Web Service for the programme
2. A bank has two types of accounts: Savings Accounts and Current Accounts. Both accounts allow customers to deposit and withdraw money and have an account number as well as an owner (a person name and address). However, they do behave differently in some aspects. Savings accounts do not allow users to withdraw more money than the current balance, but accrue interest (that is when an interest amount is calculated it is added to the account). Current accounts might have an overdraft facilities (that is a negative balance up to which withdrawels are permitted). The overdraft comes with a flat charge of 2£ per day.
You must develop a sensible class structure to capture these accounts and provide methods for their specific features (deposit, withdrawel, compute_interest, add_overdraft_charge and display_balance). Note that you do not need to handle time, that is you can assume that the bank's final code will use the compute_interest method once a month and that the add_overdraft_charge method is used daily. You will be assessed both on functionality as well as good object oriented design. Also note that you should not use a database – this exercise is about OO design and implementation.
3. Develop a web services for the bank accounts in the previous task. You will only need to implement the methods relevant to clients: deposit, withdrawel and display_balance.
VulpesRank #55 · 29.2K reputationPosted Oct 30, 2013, 1:59 PM EDT
http://www.c-sharpcorner.com/forums/thread/235328/C-Sharp.aspx
However, programming web services is not my thing and is nothing to do with the subject matter of this thread in any case. So I suggest you post the rest of the question in a new thread.
Hanook159 reputationPosted Oct 30, 2013, 10:03 PM EDT
I think you are getting error here only...
Before critical value assignment convert it to Int...
public void Update(string AppName, string critical, string Hrs)
{
SqlConnection conn = new SqlConnection(cnstr);
conn.Open();
int criticalInt = int.Parse(critical);
SqlCommand cmd = new SqlCommand("sp_Sharepoint_rs_AppsInfra_Data_Utility", conn);cmd.Parameters.Add("@mmyy", SqlDbType.VarChar, 200).Value = month.Text;
cmd.Parameters.Add("@appname", SqlDbType.VarChar,200).Value = AppName;
cmd.Parameters.Add("@critical", SqlDbType.Int).Value = criticalInt ;
cmd.Parameters.Add("@Hrs", SqlDbType.VarChar,10).Value = Hrs;
cmd.Parameters.Add("@id", SqlDbType.Int).Value = 1;
cmd.CommandType = CommandType.StoredProcedure;
cmd.ExecuteNonQuery();
conn.Close();
conn.Dispose();
}
Vignesh KumarRank #1,579 · 1K reputationPosted Oct 31, 2013, 2:28 AM EDT
Hanook159 reputationPosted Oct 31, 2013, 2:48 AM EDT
Follow this code:
assumed that critical is of type Decimal with size 4
decimal criticalInt = Decimal.Parse(critical);
SqlCommand cmd = new SqlCommand("sp_Sharepoint_rs_AppsInfra_Data_Utility", conn);cmd.Parameters.Add("@mmyy", SqlDbType.VarChar, 200).Value = month.Text;
cmd.Parameters.Add("@appname", SqlDbType.VarChar,200).Value = AppName;
cmd.Parameters.Add("@critical", SqlDbType.Decimal, 4).Value = criticalInt ;