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.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
VulpesPosted Oct 30, 2013, 8:17 AM
decimal city = Convert.ToDecimal(txtCities.Text);
HanookPosted Oct 31, 2013, 6:48 AM
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 ;
Vignesh KumarPosted Oct 31, 2013, 6:28 AM
HanookPosted Oct 31, 2013, 2:03 AM
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();
}
VulpesPosted Oct 30, 2013, 5:59 PM
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.
Sammi ShariefPosted Oct 30, 2013, 2:58 PM
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.
VulpesPosted Oct 30, 2013, 8:46 AM
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.
Vignesh KumarPosted Oct 30, 2013, 8:36 AM
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
Sanjeeb LenkaPosted Oct 30, 2013, 8:20 AM
decimal city = Convert.ToDecimal(txtCities.Text);