【问题标题】:Make sure that the class defined in this code file matches the 'inherits' attribute import确保此代码文件中定义的类与“继承”属性导入匹配
【发布时间】:2015-10-21 02:28:44
【问题描述】:

所以我是使用 VB.NET 的 asp.net 的新手,我遇到了这个错误:

编译器错误消息:ASPNET:确保此代码文件中定义的类与“继承”属性匹配,并且它扩展了正确的基类(例如 Page 或 UserControl)。

来源错误:

第 1 行:导入 System.Data.SQLite

第 2 行:导入 System.Diagnostics

源文件:C:\Projects\HousingInfo\HousingInfo\SQLiteDatabase.aspx.vb 行:1

从我所有的谷歌搜索来看,我相信这与这条线有关:

<%@ Page Language="VB" AutoEventWireup="false" CodeFile="SQLiteDatabase.aspx.vb" Inherits="SQLiteDatabase" %>

这是数据库的代码:

Imports System.Data.SQLite
Imports System.Diagnostics

Public Class SQLiteDatabase
Private Shared dbConnection As String

Public Sub New()
    dbConnection = "Data Source=housingInfo.db"
    CreateTables()
End Sub

Public Sub New(file)
    dbConnection = String.Format("Data Source={0}", file)
    CreateTables()
End Sub

<System.Web.Services.WebMethod()>
Public Shared Function CreateTables()
    Debug.WriteLine("Creating Tables")
    Dim connection = New SQLiteConnection(dbConnection)
    connection.Open()
    Try
        Dim stm As String = "CREATE TABLE IF NOT EXISTS houses(id INTEGER PRIMARY KEY AUTOINCREMENT, address TEXT, city TEXT, state TEXT, rented INTEGER)"
    Catch ex As Exception
        MsgBox("Can't create table: " & ex.Message)
    End Try
    Return Nothing
End Function
End Class

我很困惑。我的代码中可以没有 import 语句吗?

【问题讨论】:

  • 您没有继承 Page 或 UserControl -class,正如错误消息所述。将继承页面添加到您的班级

标签: asp.net vb.net inheritance


【解决方案1】:

ASP.NET “页面”必须继承自 PageUserControl 或继承自层次结构中某个点的其中之一的类。您正在“继承”SQLiteDatabase 类,它既不是 Page 也不是 UserControl

这通常由设计人员为您完成,因此您要么从头开始编写所有内容,要么将标记更改为从不同的类继承。

【讨论】:

  • 我已将Inherits Page 添加到我的 .aspx.vb 文件中,但由于某种原因,我仍然无法让客户端调用服务器端。这是 javascript sn-p:
  • @MichaelWang 你没有一个继承自Page 的代码隐藏类,它定义了CreateTables 方法吗?听起来您要么尝试自己学习,要么遵循糟糕的教程。除非您知道自己在做什么,否则您根本不必使用 Inherits 标签。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2023-01-04
  • 2012-02-05
相关资源
最近更新 更多