编译器错误信息: CS0115: “ASP.managers_do_music_aspx.GetTypeHashCode()”: 没有找到适合的方法来重写
编译错误说明: 在编译向该请求提供服务所需资源的过程中出现错误。请检查下列特定错误详细信息并适当地修改源代码。
编译器错误信息: CS0115: “ASP.managers_do_music_aspx.GetTypeHashCode()”: 没有找到适合的方法来重写
源错误:
行 1498: #line hidden
行 1499:
行 1500: public override int GetTypeHashCode() {
行 1501: return 723213337;
行 1502: }
源代码:
using System;
using System.Data;
using System.Data.SqlClient;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.IO;
public partial class Managers_Do_Music : System.Web.UI.UserControl
{
protected void Page_Load(object sender, EventArgs e)
{
if (Session["UserID"] != null)
{
name.Text = Session["username"].ToString();
BT_Delete.Enabled = true;
}
else
{
name.Text = "你尚未登录,请先登录!";
}
if (!Page.IsPostBack)
{
MusicGrid_Bind();
}
}
private void MusicGrid_Bind()
{
string ConnectionString = "server=(local);database=stu;Trusted_connection=true";
SqlConnection myConnection = new SqlConnection(ConnectionString);
String cmdText = "select * from videos";
SqlCommand myCommand = new SqlCommand(cmdText, myConnection);
myConnection.Open();
SqlDataReader recn = myCommand.ExecuteReader(CommandBehavior.CloseConnection);
///设置控件的数据源,并绑定数据
MusicGrid.DataSource = recn;
MusicGrid.DataBind();
recn.Close();
}
protected void SureBtn_Click(object sender, EventArgs e)
{
if (Session["username"] != null)
{
if ((VideoName.Text.Trim() != "") && (UpLoadVideo.PostedFile.ContentLength > 0))
{ ///首先取到上载文件的原始名称
String fileName =
UpLoadVideo.PostedFile.FileName.Substring(UpLoadVideo.PostedFile.FileName.LastIndexOf("\\"),
UpLoadVideo.PostedFile.FileName.Length - UpLoadVideo.PostedFile.FileName.LastIndexOf("\\"));
///取到当前时间的年、月、日、分、秒和毫秒的值,并使用字符串格式把它们组合成一个字符串
String fileTime = DateTime.Now.Year.ToString() + DateTime.Now.Month.ToString()
+ DateTime.Now.Day.ToString() + DateTime.Now.Hour.ToString()
+ DateTime.Now.Second.ToString() + DateTime.Now.Minute.ToString()
+ DateTime.Now.Millisecond.ToString();
///在时间字符串后面添加一个随机数和文件的后缀名
fileName = "\\" + VideoName.Text + "(" + fileTime + GetRandomint() + ")"
+ fileName.Substring(fileName.IndexOf("."), fileName.Length - fileName.IndexOf("."));
if (File.Exists(Server.MapPath(Request.ApplicationPath) + "\\classmate\\File_Data\\Music" + fileName) == false)
{
///上载文件到服务器硬盘
UpLoadVideo.PostedFile.SaveAs(Server.MapPath(Request.ApplicationPath) + "\\File_Data\\Music"
+ fileName);
///连接数据库
string connectionstring = "server=(local);database=stu;Trusted_connection=true";
string constr = ConfigurationSettings.AppSettings["ConnectionString"];
SqlConnection myConnection = new SqlConnection(connectionstring);
///更新数据库记录
String cmdText = "INSERT INTO videos (username,vauthor,vname,vurl,vbody)VALUES('" + Session["username"].ToString() + "','" + VideoAuthor.Text + "','" + VideoName.Text + "','" + "\\classmate\\File_Data\\Music" + fileName + "','" + Body.Text + "')";
SqlCommand myCommand = new SqlCommand(cmdText, myConnection);
myConnection.Open();
myCommand.ExecuteNonQuery();
myConnection.Close();
VideoAuthor.Text = "";
VideoName.Text = "";
Body.Text = "";
Response.Write("<script>alert(\"恭喜,你的上载成功!!!\")</script>");
MusicGrid_Bind();
}
else
{
Response.Write("<script>alert(\"此文件已经存在,请重命名后再上传!\")</script>");
}
}
else
{
Response.Write("<script>alert(\"文件名和内容不能为空!\")</script>");
}
}
else
{
Response.Write("<script>alert(\"你还没有登录,请先登录!!!\")</script>");
}
}
private String GetRandomint()
{
Random random = new Random();
return (random.Next(10000).ToString()); //产生一个小于10000的随机正整数
}
protected void CancelBtn_Click(object sender, EventArgs e)
{
MusicGrid_Bind();
//Response.Redirect("~/Default.aspx");
}
protected void BT_Delete_Click(object sender, EventArgs e)
{
if (Session["username"] != null)
{
foreach (DataGridItem Dgi in MusicGrid.Items)
{
CheckBox CB = (CheckBox)Dgi.FindControl("CB_Del");
if (CB.Checked)
{
string vID = Dgi.Cells[0].Text;
string DeleteStr = "Delete [videos] where vid=" + vID;
string connstring = "server=(local);database=stu;Trusted_connection=true";
SqlConnection conn = new SqlConnection(connstring);
try
{
conn.Open();
SqlCommand cmd = new SqlCommand(DeleteStr, conn);
cmd.ExecuteNonQuery();
}
catch { Response.Write("error"); Response.End(); }
finally
{
conn.Close();
}
}
}
MusicGrid_Bind();
}
else
{
Response.Write("<script>alert(\"你还没有登录,请先登录!!!\")</script>");
}
}
}
--------------------编程问答-------------------- 我也碰到这个问题。 --------------------编程问答-------------------- 原因可能是:页面中的page指令中的参数Inherits的值应该是后台类.cs的类名:
补充:.NET技术 , ASP.NET