Michael
Michael

Reputation: 318

Make sure that the class defined in this code file matches the 'inherits' attribute import

So I'm new to using asp.net with VB.NET and I'm running into this error:

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: Imports System.Data.SQLite

Line 2: Imports System.Diagnostics

Source File: C:\Projects\HousingInfo\HousingInfo\SQLiteDatabase.aspx.vb Line: 1

I believe from all my googling that it has something to do with this line:

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

This is the code for the database:

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

I'm confused. Can I not have import statements in my code?

Upvotes: 0

Views: 1429

Answers (1)

D Stanley
D Stanley

Reputation: 152566

ASP.NET "pages" must inherit from either Page, UserControl, or a class that inherits from one of those at some point in the hierarchy. you are "inheriting" the SQLiteDatabase class, which is neither a Page nor a UserControl.

Typically this is done for you by the designer, so either you're writing everything from scratch or you've changed the markup to inherit from a different class.

Upvotes: 1

Related Questions