Errors when Compiling a Class File

  • Thread starter Joe via DotNetMonster.com
  • Start date
J

Joe via DotNetMonster.com

Hi,

I'm creating a Class file that contains a function that queries the
database. I receive alot of connection type errors when I try to compile
and I'm not sure what I'm doing wrong.

This is my dataClass.vb file:


Imports System
Imports Microsoft.VisualBasic
Imports System.Web

Namespace Data

Public Class dataClass

Public Shared Function GetPage(ByVal pageNumber As Integer) As
IDataReader

Dim strConnection As String
strConnection = ConfigurationSettings.AppSettings
("ConnectionString")

Dim dbConnection As New SqlConnection(strConnection)

Dim queryString As String = "SELECT [tblPage].* From tblPage"

Dim dbCommand As New SqlCommand
dbCommand.CommandText = queryString
dbCommand.Connection = dbConnection

Dim dbParam_pageNumber As New SqlParameter
dbParam_pageNumber.ParameterName = "@PageNumber"
dbParam_pageNumber.Value = pageNumber
dbParam_pageNumber.DbType = DbType.Int32
dbCommand.Parameters.Add(dbParam_pageNumber)

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

Return dataReader

End Function


End Class
End Namespace


These are the errors I receive:

C:\Inetpub\wwwroot\web\dataClass.vb(12) : error BC30002: Type 'IDataReader'
is n
ot defined.

Public Shared Function GetPage(ByVal pageNumber As Integer) As
IDataRead
er

~~~~~~~~~
~~
C:\Inetpub\wwwroot\web\dataClass.vb(15) : error BC30451: Name
'ConfigurationSett
ings' is not declared.

strConnection = ConfigurationSettings.AppSettings
("ConnectionString"
)
~~~~~~~~~~~~~~~~~~~~~

C:\Inetpub\wwwroot\web\dataClass.vb(17) : error BC30002: Type
'SqlConnection' is
not defined.

Dim dbConnection As New SqlConnection(strConnection)
~~~~~~~~~~~~~
C:\Inetpub\wwwroot\web\dataClass.vb(21) : error BC30002: Type 'SqlCommand'
is no
t defined.

Dim dbCommand As New SqlCommand
~~~~~~~~~~
C:\Inetpub\wwwroot\web\dataClass.vb(25) : error BC30002: Type
'SqlParameter' is
not defined.

Dim dbParam_pageNumber As New SqlParameter
~~~~~~~~~~~~
C:\Inetpub\wwwroot\web\dataClass.vb(28) : error BC30451: Name 'DbType' is
not de
clared.

dbParam_pageNumber.DbType = DbType.Int32
~~~~~~
C:\Inetpub\wwwroot\web\dataClass.vb(32) : error BC30002: Type 'IDataReader'
is n
ot defined.

Dim dataReader As IDataReader = dbCommand.ExecuteReader
(CommandBehav
ior.CloseConnection)
~~~~~~~~~~~

I'm using the following Batch file to compile:

Set PATH=%SystemRoot%\Microsoft.NET\Framework\v1.1.4322
cd c:\inetpub\wwwroot\web
vbc dataClass.vb /t:library /r:System.Web.dll /out:bin\dataClass.dll
pause


Thanks so much for any help.
 
M

Manohar Kamath

You need to include the following imports:

Imports System.Configuration
Imports System.Data.SqlClient


as some of the classes you are using belong to the above namespaces.

--
Manohar Kamath
Editor, .netWire
www.dotnetwire.com


Joe via DotNetMonster.com said:
Hi,

I'm creating a Class file that contains a function that queries the
database. I receive alot of connection type errors when I try to compile
and I'm not sure what I'm doing wrong.

This is my dataClass.vb file:


Imports System
Imports Microsoft.VisualBasic
Imports System.Web

Namespace Data

Public Class dataClass

Public Shared Function GetPage(ByVal pageNumber As Integer) As
IDataReader

Dim strConnection As String
strConnection = ConfigurationSettings.AppSettings
("ConnectionString")

Dim dbConnection As New SqlConnection(strConnection)

Dim queryString As String = "SELECT [tblPage].* From tblPage"

Dim dbCommand As New SqlCommand
dbCommand.CommandText = queryString
dbCommand.Connection = dbConnection

Dim dbParam_pageNumber As New SqlParameter
dbParam_pageNumber.ParameterName = "@PageNumber"
dbParam_pageNumber.Value = pageNumber
dbParam_pageNumber.DbType = DbType.Int32
dbCommand.Parameters.Add(dbParam_pageNumber)

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

Return dataReader

End Function


End Class
End Namespace


These are the errors I receive:

C:\Inetpub\wwwroot\web\dataClass.vb(12) : error BC30002: Type 'IDataReader'
is n
ot defined.

Public Shared Function GetPage(ByVal pageNumber As Integer) As
IDataRead
er

~~~~~~~~~
~~
C:\Inetpub\wwwroot\web\dataClass.vb(15) : error BC30451: Name
'ConfigurationSett
ings' is not declared.

strConnection = ConfigurationSettings.AppSettings
("ConnectionString"
)
~~~~~~~~~~~~~~~~~~~~~

C:\Inetpub\wwwroot\web\dataClass.vb(17) : error BC30002: Type
'SqlConnection' is
not defined.

Dim dbConnection As New SqlConnection(strConnection)
~~~~~~~~~~~~~
C:\Inetpub\wwwroot\web\dataClass.vb(21) : error BC30002: Type 'SqlCommand'
is no
t defined.

Dim dbCommand As New SqlCommand
~~~~~~~~~~
C:\Inetpub\wwwroot\web\dataClass.vb(25) : error BC30002: Type
'SqlParameter' is
not defined.

Dim dbParam_pageNumber As New SqlParameter
~~~~~~~~~~~~
C:\Inetpub\wwwroot\web\dataClass.vb(28) : error BC30451: Name 'DbType' is
not de
clared.

dbParam_pageNumber.DbType = DbType.Int32
~~~~~~
C:\Inetpub\wwwroot\web\dataClass.vb(32) : error BC30002: Type 'IDataReader'
is n
ot defined.

Dim dataReader As IDataReader = dbCommand.ExecuteReader
(CommandBehav
ior.CloseConnection)
~~~~~~~~~~~

I'm using the following Batch file to compile:

Set PATH=%SystemRoot%\Microsoft.NET\Framework\v1.1.4322
cd c:\inetpub\wwwroot\web
vbc dataClass.vb /t:library /r:System.Web.dll /out:bin\dataClass.dll
pause


Thanks so much for any help.
 
J

Joe via DotNetMonster.com

I had tried that but got the following error:

error BC30466: Namespace or type 'SqlClient' for the Imports
'System.Data.SqlClient' cannot be found

Thanks
 
M

Matt Berther

Hello Joe via DotNetMonster.com,

You'll also need to add a reference to System.Data.dll.
 

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

Similar Threads

Timing out 9
Common Functions 3
Variable from datareader 1
Connection 8
Uploading a file on a remote server. 1
Passing a Variable 5
Passing a Variable from a dataview 1
Business Component missing dlls 14

Top