1

I have an issue in conversion. What is wrong with this conversion?

Here is the error:

Compilation Error Description: An error occurred during the compilation of a resource required to service this request. Please review the following specific error details and modify your source code appropriately.

Compiler Error Message: CS0029: Cannot implicitly convert type 'long' to 'string'

if (hid_Action.Value.ToString().ToUpper() == "RENEW")
{
    string strHFUpdate = string.Empty;
    string srt = Convert.ToInt64(Session["AppId"] + ",'" + Session["CAAID"].ToString() + "','" + Session["UserType"].ToString() + "'");
    strHFUpdate = "oea_sp_update_HF_MC_Renewal_Status " + srt;
    rProxy.GlobalSaveData(Session["CountyName"].ToString().Trim(), strHFUpdate.ToString());
}
1

3 Answers 3

3

Here is the problem

string srt = Convert.ToInt64

You are trying to assign a long value to a string. You can't. You have to use .ToString() to change it into a string, then you will be able to assign.

And one more error, Convert.ToInt64 doesn't convert number with float points, meaning 1.1 will throw an exception. An the string you are trying to convert is totally invalid, what was it supposed to do?

Sign up to request clarification or add additional context in comments.

3 Comments

This is what my predecessor wrote:
if (hid_Action.Value.ToString().ToUpper() == "RENEW") { string strHFUpdate = string.Empty; strHFUpdate = "oea_sp_update_HF_MC_Renewal_Status " + Convert.ToInt64(Session["AppId"].ToString() + ",'" + Session["CAAID"].ToString() + "','" + Session["UserType"].ToString() + "'"); rProxy.GlobalSaveData(Session["CountyName"].ToString().Trim(), strHFUpdate.ToString()); }
And i am getting this error: Input string was not in a correct format. Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code. Exception Details: System.FormatException: Input string was not in a correct format.
2
 string srt = Convert.ToInt64(...);

Yes, that cannot work. Hard to guess what was intended here, maybe a missing parenthesis.

1 Comment

So what is the solution? How does one convert a long to a string?
0

You can't convert a string with commas and single-quotes into a number, additionally, both ToInt64() overloads take a second parameter:

Your code above is trying to implicitly cast the string into another data-type that ToInt64() can take for an overload with a single parameter. ToInt64() does support converting from string but both those overloads take two parameters (see below)

[ From MSDN: http://msdn.microsoft.com/en-us/library/system.convert.toint64.aspx ]

ToInt64(String, IFormatProvider) Converts the specified string representation of a number to an equivalent 64-bit signed integer, using the specified culture-specific formatting information.

ToInt64(String, Int32) Converts the string representation of a number in a specified base to an equivalent 64-bit signed integer.

But as I mentioned, even if you did use the correct overloaded function, your string would not be parse-able due to the non-numeric characters.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.