【问题标题】:no suitable method found to override error on Asp.net没有找到合适的方法来覆盖 Asp.net 上的错误
【发布时间】:2011-03-01 19:52:15
【问题描述】:

我是 asp.net 的新手。我写了一页asp.net,但是运行时出现如下错误。

 public partial class Issueofbook: System.Web.UI.Page
 {
public Int64 Sid;
protected void Page_Load(object sender, EventArgs e)
{
    string Id;
    Id = Request.QueryString.Get(0);

    if (!(IsPostBack == true))
    {
        if (Request.QueryString.Get(1) == "G")
        {
            Sid = Convert.ToInt64(Id);
            if (PopulatedRecord (Sid ) == false)
            {

            }
        }
     }
 }
 private Boolean PopulatedRecord(Int64 Id)
   {
    DataSet DS;
    DS = new DataSet();
    SqlCommand cmd = new SqlCommand();
    SqlDataAdapter da = new SqlDataAdapter();
    SqlConnection Cnn = new SqlConnection();
    string connectionstring;
    connectionstring = @"Datasource=DEVI\SQLEXPRESS;Intial catalog=librarymanagement;Integrated Security=SSPI";
    Cnn.ConnectionString = connectionstring;
    if (Cnn.State != ConnectionState.Open)
        Cnn.Open();
    cmd.Connection = Cnn;
    cmd.CommandType = CommandType.StoredProcedure;
    cmd.CommandText = "usbinsertdatainto";
    cmd.Parameters.Clear();
    cmd.Parameters.AddWithValue("@bookno", "no");
    Adp.SelectCommand = Cmd;
    try
    {
        Adp.Fill(Ds);
    }
    catch (Exception ex)
    {
        throw new ApplicationException(
            "!!! An Error Occured While Update Record In Dtl_SecurityCapital_Upload." + ex.Message);
        lblError.Visible = true;
        lblError.Text = "!!! An Error Occured While " + ex.Message.ToString();
        return false;
    }
    if (DS.Tables[0].Rows.Count > 0)
    {
        txtno.Text = DS.Tables[0].Rows[0]["bookno"].ToString();
        txtstuno.Text = DS.Tables[0].Rows[0]["studentno"].ToString();
        RadioButton1.Text = DS.Tables[0].Rows[0]["currentnoofcopiesavaillable"].ToString();
        RadioButton2.Text = DS.Tables[0].Rows[0]["currentnoofcopiesavaillable"].ToString();
        txtdate.Text = DS.Tables[0].Rows[0]["IssueDate"].ToString();
        txtddate.Text = DS.Tables[0].Rows[0]["Duedate"].ToString();
    }
    cmd.Dispose();
    Cnn.Close();
    Cnn.Dispose();
    return true;
}

protected void Button2_Click(object sender, EventArgs e)
{
    SqlConnection Cnn = new SqlConnection();
    string constr = null;
    SqlCommand cmd = new SqlCommand();
    constr = @"Data Source=DEVI\SQLEXPRESS; Initial Catalog =librarymanagement; Integrated Security=SSPI";
    Cnn.ConnectionString =constr;
    try
    {
        if (Cnn.State != ConnectionState.Open)
            Cnn.Open();
    }
    catch (Exception ex)
    {
        string str1 = null;
        str1 = ex.ToString();
    }
    cmd.Connection = Cnn;
    cmd.CommandType = CommandType.StoredProcedure;
    cmd.CommandText = "uspInsertbookDatainto";
    cmd.Parameters.Clear();
    cmd.Parameters.AddWithValue("@bookno", txtno.Text);
    cmd.Parameters.AddWithValue("@studentno", txtstuno.Text);
    cmd.Parameters.AddWithValue("@Issuedate", txtdate.Text);
    cmd.Parameters.AddWithValue("@Duedate", txtddate.Text);
    if (RadioButton1.Checked==true)
    {
        cmd.Parameters.AddWithValue("@currentnoofcopiesavaillable", RadioButton1.Text);
    }
    if (RadioButton2.Checked == true)
    {
        cmd.Parameters.AddWithValue("@currentnoofcopiesavaillable", RadioButton2.Text);
    }
    try
    {
        cmd.ExecuteNonquery();
    }
    catch (Exception ex)
    {
        throw new ApplicationException("!!! An error an occured while Insert Record Dtl_SecurityCapital_Upload." + ex.Message);
        lblerror.Visible = true;
        lblerror.Text = "!!! An Error occured while ." + ex.Message.ToString();
    }

    finally
    {
        cmd.Dispose();
    }
    Cnn.Close();
    lblError.Text = "New Issue of record suceessfully!!";
    txtno.Text = "";
    txtstuno.Text = "";
    txtdate.Text = "";
    txtddate.Text = "";
}
}

说明:

编译服务此请求所需的资源时出错。请查看以下具体错误详情并适当修改您的源代码。

编译器错误信息:

CS0115: 'ASP.issue_of_book_aspx.GetTypeHashCode()': no suitable method found to override

来源错误:

Line 1253:        
Line 1254:        [System.Diagnostics.DebuggerNonUserCodeAttribute()]
Line 1255:        public override int GetTypeHashCode() {
Line 1256:            return -853658727;
Line 1257:        }

有人会指导我吗?谢谢。

【问题讨论】:

  • 没有任何示例代码我们无法判断问题所在
  • @Dorababu 我添加了我的代码,你会检查一下吗
  • 显然您没有覆盖此代码中的方法。但是,它是一个部分类,您可以在 GetTypeHashCode 上进行搜索并检查它是否在也是该类的其他文件中被覆盖?我知道它应该是一个部分类,因为它是一个 aspx 代码隐藏文件,但最好确保它不会在其他地方使用(偶然?)
  • 您的代码似乎没有任何覆盖,所以您能否提供完整的堆栈跟踪...我们将看到错误是从哪里生成的
  • 看到这个你的页面被定义为 Issueofbook 并从源代码中检查你在设计部分后给出的名称

标签: asp.net


【解决方案1】:

看看这篇文章可能对你有帮助

http://technage.blogspot.com/2008/05/error-gettypehashcode-no-suitable.html

根据我的观察,您的继承名称表示 issue_of_book_aspx.cs,在您的代码中,您将名称显示为 Issueofbook,因此这会有所不同并引发错误,请确保您的 .aspx 和 .aspx.cs 名称应该相同

【讨论】:

    猜你喜欢
    • 2013-05-18
    • 2020-07-01
    • 2022-08-07
    • 2019-11-05
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-07-07
    相关资源
    最近更新 更多