Results 1 to 5 of 5

Thread: Program wont Compile

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Mar 2002
    Posts
    68

    Program wont Compile

    I cant get this program to compile. I have a Vb class file called dbconn.vb
    which has the Database stuff in it and a function called "fallen".
    When I try to access the "fallen" function from my Aspx file Visual Studio returns an error " Name fallen is not declared".
    What did I miss
    Thanks for the help the code is below.



    dbconn.vb
    Code:
    Imports System.Data.SqlClient
    
    Public Class dbconn
    
        Private Shared ReadOnly Property ConnectionString() As String
    
            Get
                Return ConfigurationSettings.AppSettings("ConnectionString")
    
            End Get
    
        End Property
    
     Public Function GetEmployeeName()
            'Public Function GetEmployeeName() As SqlDataReader
            ' Create the connection object
            Dim SqlConnection As New SqlConnection(ConnectionString)
    
            'Create the command object
            Dim command As New SqlCommand("Select * from Employess", SqlConnection)
            Try
                SqlConnection.Open()
    
    
            Catch ex As Exception
    
            End Try
            SqlConnection.Close()

    weborm1.aspx


    Code:
     
    Public Class WebForm1
        Inherits System.Web.UI.Page
    #Region " Web Form Designer Generated Code "
    
        'This call is required by the Web Form Designer.
        <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
    
        End Sub
        Protected WithEvents TextBox1 As System.Web.UI.WebControls.TextBox
        Protected WithEvents TextBox2 As System.Web.UI.WebControls.TextBox
        Protected WithEvents Label1 As System.Web.UI.WebControls.Label
        Protected WithEvents Label2 As System.Web.UI.WebControls.Label
        Protected WithEvents Button1 As System.Web.UI.WebControls.Button
    
        'NOTE: The following placeholder declaration is required by the Web Form Designer.
        'Do not delete or move it.
        Private designerPlaceholderDeclaration As System.Object
    
        Private Sub Page_Init(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Init
            'CODEGEN: This method call is required by the Web Form Designer
            'Do not modify it using the code editor.
            InitializeComponent()
        End Sub
    
    #End Region
    
        Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
            'Put user code to initialize the page here
    
        End Sub
    
        Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
            fallen()
        End Sub
    
    End Class

  2. #2
    Frenzied Member Mike Hildner's Avatar
    Join Date
    Jul 2002
    Location
    Des Moines, NM
    Posts
    1,690

    Re: Program wont Compile

    A couple things. One, I don't see in your dbconn class where the fallen method is defined (did you copy and paste that part?). Second, in your WebForm1, you call it as "fallen()". Assuming it was a shared method in dbconn, you'd have to call it like "dbconn.fallen()". If it's not a shared method, you need an instance reference first.

  3. #3
    Addicted Member rdove's Avatar
    Join Date
    Dec 2002
    Location
    Indianapolis
    Posts
    251

    Re: Program wont Compile

    maybe its just me, but I do not even see the a function called fallen in the dbconn.vb code that was posted. So from what I see, that is the problem.
    ~Ryan





    Have I helped you? Please Rate my posts.

  4. #4

    Thread Starter
    Lively Member
    Join Date
    Mar 2002
    Posts
    68

    Re: Program wont Compile

    Forgot to copy the entire code. Here it is with the function "fallen"
    Code:
    Imports System.Data.SqlClient
    
    Public Class dbconn
    
        Private Shared ReadOnly Property ConnectionString() As String
    
            Get
                Return ConfigurationSettings.AppSettings("ConnectionString")
    
            End Get
    
        End Property
        Public Function GetEmployeeName()
            'Public Function GetEmployeeName() As SqlDataReader
            ' Create the connection object
            Dim SqlConnection As New SqlConnection(ConnectionString)
    
            'Create the command object
            Dim command As New SqlCommand("Select * from Employess", SqlConnection)
            Try
                SqlConnection.Open()
    
    
            Catch ex As Exception
    
            End Try
            SqlConnection.Close()
    
        End Function
    
        Public Function fallen()
    
        End Function
    
    
    End Class

  5. #5
    Hyperactive Member tailz's Avatar
    Join Date
    Jul 2002
    Posts
    306

    Re: Program wont Compile

    You either need to declare an instance of the class "dbconn" to access "fallen" like so:

    Code:
    dim x as New dbconn
    x.fallen
    or

    You need to declare "fallen" as a shared function then dbconn.fallen will work.(you can import dbconn, in which case just do "fallen" will work) - like so:

    Code:
    Public Shared Function Fallen() 
    'DO Stuff
    End Function
    if the function has no relevance to the class that it is in, you should either create a new class or by putting the function in a module it will make it publicly accessible...
    Last edited by tailz; Dec 9th, 2004 at 06:19 AM.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width