开发者

Compilation error in asp.net page

I am getting this message in my asp.net page.

Any suggestions to resolve this will be greatly appreciated. Thx.

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: ASPNET: Make sure that the class defined in this code file matches the 'inherits' attribute, and that it extends the correct base class (e.g. Page or UserControl).

Source Error:

Line 1:  using System;
Line 2:  using System.Data;
Line 3:  using System.Data.SqlClient;

The aspx code is:

<%@ Page Language="C#" AutoEventWireup="true"  CodeFile="Default.aspx.cs" Inherits="_Default" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://ww开发者_如何学运维w.w3.org/1999/xhtml">
<head runat="server">
  <title>Untitled Page</title>
</head>
<body>
  <form id="form1" runat="server">
    <div>

    </div>
  </form>
</body>
</html>

The C# code is:

using System;
using System.Data;
using System.Data.SqlClient;


class SqlConnectionDemo
{
    static void Main()
    {
        SqlConnection conn = SqlConnection("Data Source=(local); Initial Catalog=JobSearchManager;Integrated Security = SSPI");
        SqlDataReader rdr = null;

        try
        {
            conn.Open();
            SqlCommand cmd = new SqlCommand("select * from Agency", conn);
            rdr = cmd.ExecuteReader;
            while (rdr.Read())
            {
                Console.WriteLine(rdr[0]);
            }
        }
        finally
        {
            if (rdr != null)
            {
                rdr.Close();
            }
            if (conn != null)
            {
                conn.Close;
            }
        }
    }
}


Your aspx code says Inherits="_Default" but your class is called SqlConnectionDemo. These need to match.


Your C# code is not the code behind for that web page (or any web page). It should have something like this at the beginning of the class:

class _Default : System.Web.Page {

Your class has a Main method, as if it was from a console application instead. Have you pasted a database example over the original code behind class?


Do you have a class file named "Default.aspx.cs" that looks like this?

using System;

namespace YourApplicationName
{
    public partial class _Default : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {

        }
    }
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜