无法将类型'object'隐式转换为'int'.存在显式转换(您是否缺少演员表?)
大家好,
C#中的新手,出现了给定的错误,
无法将类型"object"隐式转换为"int".存在显式转换(您是否缺少演员表?)
源错误:
第262行:int verifycount_result = 0;
第263行:
第264行:verifycount_result = Destinations_Alloc_Count();
265行:
第266行:if(verifycount_result =="1")
我的代码是:
hi all,
am new in c#, i got the given error,
Cannot implicitly convert type ''object'' to ''int''. An explicit conversion exists (are you missing a cast?)
Source Error:
Line 262: int verifycount_result=0;
Line 263:
Line 264: verifycount_result = Destinations_Alloc_Count();
Line 265:
Line 266: if(verifycount_result=="1")
my code is:
int verifycount_result=0;
verifycount_result = Destinations_Alloc_Count();
if(verifycount_result=="1")
{
public object Destinations_Alloc_Count()
{
string result = null;
result = "";
try
{
SqlConnection con = new SqlConnection(sqlconn_cmsstr);
if (con.State == ConnectionState.Closed)
{
con.Open();
}
SqlCommand cmd = new SqlCommand("select count(divertedto) from Hotdial where accountnumber='" + Session["user_id"] + "'", con);
int i = 0;
i = 0;
i = int.Parse(cmd.ExecuteScalar());
if (i > 200)
{
result = "0";
return result;
}
else
{
result = "1";
return result;
}
}
catch (Exception ex)
{
result = "-1";
return result;
}
}
这类似于您的其他问题
您的函数正在返回一个对象.在函数内,您将返回一个字符串.调用函数时,就是将其分配给int!
1)更改函数以返回类型字符串.
This is similar to your other question
Your function is returning an object. Within the function, you are returning a string. When you are calling the function, you are assigning it to an int!
1) Change your function to return type string.
public string Destinations_Alloc_Count()
2)将变量更改为字符串类型
2) Change your variable to be a string type
string verifycount_result = string.Empty;
verifycount_result = Destinations_Alloc_Count();
尝试保持相同的类型,否则您将遇到类似这样的问题
Try and keep your types the same, or you will have issues like this