错误54'scharttype.MyMethod()':并非所有代码路径都返回一个值 [英] Error 54 'charttype.MyMethod()': not all code paths return a value

查看:71
本文介绍了错误54'scharttype.MyMethod()':并非所有代码路径都返回一个值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

目标 - 希望以图表形式显示





我的CS页面



 使用系统; 
使用 System.Collections.Generic;
使用 System.Linq;
使用 System.Web;
使用 System.Web.UI;
使用 System.Web.UI.WebControls;
使用 System.Web.Services;
使用 MySql.Data.MySqlClient;
使用 System.Web.Script.Serialization;

public partial class charttype:System.Web.UI.Page
{
protected void Page_Load( object sender,EventArgs e)
{
try
{
string a1 =会话[ 。用户名]的ToString();
string a2 =会话[ pass ]的ToString();
}
catch (例外错误)
{
// Server.Transfer(AdminLogin1.aspx);
}


string firstname = ,lastname = ;
尝试
{
firstname =会话[ 名字]的ToString();
}
catch (例外错误)
{

}

尝试
{
lastname =会话[ 姓氏]的ToString();
}
catch (异常错误)
{

}
尝试
{
Label11.Text = 您好, + firstname + + lastname;
}
catch (异常错误)
{

}
}

[WebMethod]
public static string MyMethod() // 此行显示错误
{

解决方案

当您向我们展示一个代码片段时,通常会向我们展示显示问题的部分,而不是位以上......



但是,既然你的方法返回一个字符串,并且错误信息很明显,那就很明显了:编译器发现有至少有一条通过MyMethod方法的路径,该路径不会产生 return 语句。这可能是因为您忘记将其作为结尾,或者您有一个 if 条件返回一个字符串,并且 else 那不是。



但是你没有向我们展示代码,所以你应该看看它并找出哪个代码一段代码错了!


ASPX页面

]]>





< asp:content id =Content1contentplaceholderid =HeadContentrunat =Serverxmlns:asp =#unknown>



< asp:content id =Content2contentplaceholderid =MainContentrunat =Serverxmlns:asp =#unknown>















<% - - %>





google.load('visualization','1',{packages:['corechart']} );



]]>





(文件)。就绪( function(){



Aim-Want to display in chart form


My CS page

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.Services;
using MySql.Data.MySqlClient;
using System.Web.Script.Serialization;

public partial class charttype : System.Web.UI.Page
{
  protected void Page_Load(object sender, EventArgs e)
    {
        try
        {
            string a1 = Session["username"].ToString();
            string a2 = Session["pass"].ToString();
        }
        catch (Exception err)
        {
            //Server.Transfer("AdminLogin1.aspx");
        }


        string firstname = "", lastname = "";
        try
        {
            firstname = Session["firstname"].ToString();
        }
        catch (Exception err)
        {

        }

        try
        {
            lastname = Session["lastname"].ToString();
        }
        catch (Exception err)
        {

        }
        try
        {
            Label11.Text = "Hi,    " + firstname + "  " + lastname;
        }
        catch (Exception err)
        {

        }
    }

  [WebMethod]
  public static string MyMethod()  //This line is showing error
  {

解决方案

When you show us a code fragment, it is normally an idea to show us the section showing teh problem, rather than the bit above that...

But, since your method returns a string, and the error message is pretty explicit, it is fairly obvious: the compiler has found that there is at least one path through your MyMethod method which does not result in a return statement. This can be because you forgot to put it as the end, or that you have an if condition that returns a string, and an else that doesn't.

But you didn't show us the code, so it will be up to you to look at it and work out which piece of code is wrong!


ASPX PAGE
]]>


<asp:content id="Content1" contentplaceholderid="HeadContent" runat="Server" xmlns:asp="#unknown">

<asp:content id="Content2" contentplaceholderid="MainContent" runat="Server" xmlns:asp="#unknown">







<%----%>


google.load('visualization', '1', { packages: ['corechart'] });

]]>



(document).ready(function () {


这篇关于错误54'scharttype.MyMethod()':并非所有代码路径都返回一个值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆