Common Functions

  • Thread starter Pete via DotNetMonster.com
  • Start date
P

Pete via DotNetMonster.com

Hi,

I've created a class that contains a common function. When I try to invoke
the function or method, I get the error:
BC30451: Name 'dataClass' is not declared.

The class file dataClass.vb contains the following:
Imports System
Namespace MySpace
Public Class dataClass
Public Shared Function GetPage(ByVal pageNumber As Integer, ByVal
lessonNumber As Integer, ByVal courseNumber As Integer) As
System.Data.IDataReader
Dim strConnection As String
strConnection = ConfigurationSettings.AppSettings
("ConnectionString")

Dim dbConnection As System.Data.IDbConnection = New
System.Data.SqlClient.SqlConnection(strConnection)

Dim queryString As String = "SELECT [tblPage].*, [tblLesson].
[LessonNumber], [tblCourse].[CourseNumber] FROM [tblPage], [tblLesson],
[tblCourse] WHERE (([tblPage].[Pa"& _
"geNumber] = @PageNumber) AND ([tblLesson].[LessonNumber] =
@LessonNumber) AND (["& _
"tblCourse].[CourseNumber] = @CourseNumber)) AND
tblPage.lessonID = tblLesson.lessonID AND tblLesson.CourseID =
tblCourse.CourseID"
Dim dbCommand As System.Data.IDbCommand = New
System.Data.SqlClient.SqlCommand
dbCommand.CommandText = queryString
dbCommand.Connection = dbConnection

Dim dbParam_pageNumber As System.Data.IDataParameter = New
System.Data.SqlClient.SqlParameter
dbParam_pageNumber.ParameterName = "@PageNumber"
dbParam_pageNumber.Value = pageNumber
dbParam_pageNumber.DbType = System.Data.DbType.Int32
dbCommand.Parameters.Add(dbParam_pageNumber)
Dim dbParam_lessonNumber As System.Data.IDataParameter = New
System.Data.SqlClient.SqlParameter
dbParam_lessonNumber.ParameterName = "@LessonNumber"
dbParam_lessonNumber.Value = lessonNumber
dbParam_lessonNumber.DbType = System.Data.DbType.Int32
dbCommand.Parameters.Add(dbParam_lessonNumber)
Dim dbParam_courseNumber As System.Data.IDataParameter = New
System.Data.SqlClient.SqlParameter
dbParam_courseNumber.ParameterName = "@CourseNumber"
dbParam_courseNumber.Value = courseNumber
dbParam_courseNumber.DbType = System.Data.DbType.Int32
dbCommand.Parameters.Add(dbParam_courseNumber)

dbConnection.Open
Dim dataReader As System.Data.IDataReader =
dbCommand.ExecuteReader(System.Data.CommandBehavior.CloseConnection)

Return dataReader
End Function
End Class
End Namespace


When trying to invoke it, I use:
<ASP:Repeater id="RepeaterPageText" runat="server" DataSource="<%#
dataClass.GetPage(1,1,1) %>">
<ItemTemplate>
<%# DataBinder.Eval(Container.DataItem, "pageText") %>
</ItemTemplate>
</ASP:Repeater>

Am I supposed to declare the class in the page I'm going to use? The class
file exists in the root of the application.

Thanks
 
S

Scott Allen

Hi Pete:

If your class is being built as part of the same project, you'll just
need an Imports for the namespace in your aspx, or fully qualify the
type name.

<%@ Import namespace="MySpace" %>

--
Scott
http://www.OdeToCode.com/blogs/scott/

Hi,

I've created a class that contains a common function. When I try to invoke
the function or method, I get the error:
BC30451: Name 'dataClass' is not declared.

The class file dataClass.vb contains the following:
Imports System
Namespace MySpace
Public Class dataClass
Public Shared Function GetPage(ByVal pageNumber As Integer, ByVal
lessonNumber As Integer, ByVal courseNumber As Integer) As
System.Data.IDataReader
Dim strConnection As String
strConnection = ConfigurationSettings.AppSettings
("ConnectionString")

Dim dbConnection As System.Data.IDbConnection = New
System.Data.SqlClient.SqlConnection(strConnection)

Dim queryString As String = "SELECT [tblPage].*, [tblLesson].
[LessonNumber], [tblCourse].[CourseNumber] FROM [tblPage], [tblLesson],
[tblCourse] WHERE (([tblPage].[Pa"& _
"geNumber] = @PageNumber) AND ([tblLesson].[LessonNumber] =
@LessonNumber) AND (["& _
"tblCourse].[CourseNumber] = @CourseNumber)) AND
tblPage.lessonID = tblLesson.lessonID AND tblLesson.CourseID =
tblCourse.CourseID"
Dim dbCommand As System.Data.IDbCommand = New
System.Data.SqlClient.SqlCommand
dbCommand.CommandText = queryString
dbCommand.Connection = dbConnection

Dim dbParam_pageNumber As System.Data.IDataParameter = New
System.Data.SqlClient.SqlParameter
dbParam_pageNumber.ParameterName = "@PageNumber"
dbParam_pageNumber.Value = pageNumber
dbParam_pageNumber.DbType = System.Data.DbType.Int32
dbCommand.Parameters.Add(dbParam_pageNumber)
Dim dbParam_lessonNumber As System.Data.IDataParameter = New
System.Data.SqlClient.SqlParameter
dbParam_lessonNumber.ParameterName = "@LessonNumber"
dbParam_lessonNumber.Value = lessonNumber
dbParam_lessonNumber.DbType = System.Data.DbType.Int32
dbCommand.Parameters.Add(dbParam_lessonNumber)
Dim dbParam_courseNumber As System.Data.IDataParameter = New
System.Data.SqlClient.SqlParameter
dbParam_courseNumber.ParameterName = "@CourseNumber"
dbParam_courseNumber.Value = courseNumber
dbParam_courseNumber.DbType = System.Data.DbType.Int32
dbCommand.Parameters.Add(dbParam_courseNumber)

dbConnection.Open
Dim dataReader As System.Data.IDataReader =
dbCommand.ExecuteReader(System.Data.CommandBehavior.CloseConnection)

Return dataReader
End Function
End Class
End Namespace


When trying to invoke it, I use:
<ASP:Repeater id="RepeaterPageText" runat="server" DataSource="<%#
dataClass.GetPage(1,1,1) %>">
<ItemTemplate>
<%# DataBinder.Eval(Container.DataItem, "pageText") %>
</ItemTemplate>
</ASP:Repeater>

Am I supposed to declare the class in the page I'm going to use? The class
file exists in the root of the application.

Thanks
 
P

Pete via DotNetMonster.com

Thanks. I tried adding the namespace but it still comes up that the method
or function is undeclared. Do I need to add a path to the namespace? How
would you fully qualify the type name?
 
S

Scott Allen

Hi Pete:

The <%@ Import namespace="MySpace" %> directive will include the
namespace.

Are you using Visual Studio .NET to build - or another tool? Make sure
the class is compiled by including the file in your project. Now that
I read your message again, it sounds like you are trying to include
the class by just placing the file in the root directory - but you''ll
need it to compile too.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top