0

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?

1
  • You are not inheriting the Page or UserControl -class, just as the error message states. Add Inherits Page to your class Commented Oct 20, 2015 at 18:22

1 Answer 1

1

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.

Sign up to request clarification or add additional context in comments.

2 Comments

I've add Inherits Page to my .aspx.vb file but for some reason I still cannot get the client to call server side. Here's the javascript snippet: <script type='text/javascript'> function CreateTables() { PageMethods.CreateTables(); } </script>
@MichaelWang Do you not have a code-behind class that inherits from Page that has the CreateTables method defined? Sounds like you're either trying to learn on your own or following a bad tutorial. You shouldn't have to monkey with the Inherits tag at all unless you know what you're doing.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.