PDA

Click to See Complete Forum and Search --> : Program wont Compile


gearbolt
Dec 8th, 2004, 09:40 PM
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

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



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

Mike Hildner
Dec 8th, 2004, 09:58 PM
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.

rdove
Dec 8th, 2004, 10:09 PM
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.

gearbolt
Dec 8th, 2004, 10:39 PM
Forgot to copy the entire code. Here it is with the function "fallen"

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

tailz
Dec 9th, 2004, 05:08 AM
You either need to declare an instance of the class "dbconn" to access "fallen" like so:


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:


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...