2011-06-13 247 views
0

我在转换中遇到问题。 Whate对这种转换是错误的吗?编译器错误消息:无法将类型'long'隐式转换为'string'

以下是错误:

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()); 
} 

感谢您的帮助!

+0

Not enough information ...什么脚本语言?很明显C#但你应该写下来并标记它 – Omer 2011-06-13 18:10:50

+0

可能是我没有正确理解你,但它是用asp.net,C#编写的。 – userstackoverflow 2011-06-13 18:13:47

+0

这可能会帮助你:-http://social.msdn.microsoft.com/forums/en-US/csharpgeneral/thread/35a1ffd9-b82a-435d-9efb-2e8a779d24c0/ – 2011-06-13 18:15:05

回答

3
string srt = Convert.ToInt64(...); 

是的,那是行不通的。很难猜测这里的目的是什么,也许是一个缺失的括号。

0

这里的问题是

string srt = Convert.ToInt64 

您试图分配long值到string。你不能。您必须使用.ToString()将其更改为字符串,然后才能分配。

还有一个错误,Convert.ToInt64不会将浮点数转换为数字,这意味着1.1会引发异常。你想要转换的字符串是完全无效的,它应该做什么?

+0

这是我的前任写道: – userstackoverflow 2011-06-13 18:19:28

+0

if(hid_Action.Value.ToString()。ToUpper()==“RENEW”) { string strHFUpdate = string.Empty; ()“+”','“+ Session [”UserType“]。”ToString()+“,'”+ Session [“CAAID”]。 .ToString()+“'”); rProxy.GlobalSaveData(Session [“CountyName”] .ToString()。Trim(),strHFUpdate.ToString()); } – userstackoverflow 2011-06-13 18:20:04

+0

而我得到这个错误:输入字符串不是正确的格式。 描述:执行当前Web请求期间发生未处理的异常。请查看堆栈跟踪以获取有关该错误的更多信息以及源代码的位置。 异常详细信息:System.FormatException:输入字符串的格式不正确。 – userstackoverflow 2011-06-13 18:21:06

0

你不能用逗号和单引号字符串转换成一个数字,此外,这两种ToInt64()重载采用第二个参数:

你上面的代码试图将字符串隐式转换为另一种数据类型的ToInt64()可以采取一个单一的参数超载。 ToInt64()不支持从字符串转换,但是这两个重载需要两个参数(见下文)

[从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.

但正如我所说,即使你没有使用正确的重载函数,由于非数字字符,您的字符串不会被解析。

相关问题