Link to home
Start Free TrialLog in
Avatar of cmgarnett
cmgarnettFlag for United Kingdom of Great Britain and Northern Ireland

asked on

Imports problem using vbc

I am trying to learn a little bit about ASP.NET and so I have armed myself with Web Matrix and a book of examples to work through, "ASP.NET at Work".

Early on I have been introduced to the idea of creating a DLL called database.dll and using it in my pages. I compiled it into the bin folder using a make.bat file to run a command line
"vbc /debug /nologo /t:library /out:%1.dll /r:System.dll /r:System.Xml.dll /r:System.Web.dll /r:System.Data.dll %1.vb"

Everything seemed to work as expected and my pages were able to use the new Databse.dll.

The next stage was to create another DLL which imports the previously compiled database.dll. When I try to compile it I get numerous errors, the first of which suggests that the Database.dll cannot be found. "BC30466: Namespace or type 'Database' for the Imports 'Database' cannot be found." This problem presumably leads to some of the errors that follow.

My question is how can I compile a dll which imports a dll that I have already compiled using VBC?
Avatar of graye
graye
Flag of United States of America image

Check out the /libpath option...   You can either put the Database.dll in the Global Assembly Cache (GAC) or you can specify the path to the DLL

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/vblr7/html/vaconInvokingCommandLineCompiler.asp
Avatar of cmgarnett

ASKER

Thanks for your reply graye.

It looks to me as if the LibPath option is relevant if you are not in the current working directory and I think I am.

I have opened an MS-Dos session and used CD to navigate to the folder with my source and dll files. This folder is a bin folder beneath my project folder. My PATH variable includes C:\WINNT\Microsoft.NET\Framework\v1.1.4322 in it so that I can run vbc.exe from my bin folder.

This is the database.vb file that compiles successfully and can be used by importing it into aspx pages....

Imports System.Data
Imports System.Data.OleDb
Imports System.Configuration

Namespace Database

      Public Class Database

            Private m_oConn As OleDbConnection

            Public Sub New()

                  Dim oConf As ConfigurationSettings

                  If oConf.AppSettings("ConnectionString") = "" Then
                        'Throw New Exception("Connection string not found in application configuration file.")
                  Else
                        m_oConn = New OleDbConnection(oConf.AppSettings("ConnectionString").ToString)
                        m_oConn.Open()
                  End If

            End Sub

            'Public Sub New(ByVal sConnectionString As String)

            '      m_oConn = New OleDbConnection(sConnectionString)
            '      m_oConn.Open()

            'End Sub

            'so that other objects can use the connection
            'Public ReadOnly Property Connection() As OleDbConnection

            '      Get
            '            Return m_oConn
            '      End get

            'End Property

            Public Function Execute(ByVal sSQL As String) As Integer

         Dim lRecords As Long
            Dim oCmd As New OleDbCommand

            oCmd.Connection = m_oConn
            oCmd.CommandText = sSQL
            oCmd.CommandType = CommandType.Text

            lRecords = oCmd.ExecuteNonQuery()

            Return lRecords

            End function

            Public Function GetDataReader(ByVal sSQL As String) As OleDbDataReader

            Dim oCmd As New OleDbCommand
            Dim oDR As OleDbDataReader

            oCmd.Connection = m_oConn
            oCmd.CommandText = sSQL
            oCmd.CommandType = CommandType.Text

            oDR = oCmd.ExecuteReader

            'oDR.Read()

            Return oDR

            End function

            'Public Function GetDataSet(ByVal sSQL As String) As OleDbDataSet

         '    Dim oDA As New OleDbdataAdapter(sSQL, m_oConn)
         '    Dim oDS As OleDbDataReader("Results")

         '    oDA.Fill(oDS)
         '    Return oDS

            'End function

            Public Sub Close()

                  m_oConn.Close()

            End Sub

      End Class

End Namespace

This is the baseclass.vb file that should use the previously compiled database.dll file....

Imports System.Text
Imports System.Collections
Imports Database

Namespace BaseClass

   Public MustInherit Class BaseClass

      Private m_aErrors As ArrayList
      Protected m_oDB As Database
      Protected m_oDA As OleDbDataAdapter
      Protected m_oCB As OleDbCommandBuilder
      Protected m_oDS As OleDbsDataSet

      Protected Sub New(ByVal oDB As Database, ByVal sSQL As String)

         m_oDB = oDB
         m_oDA = New OleDbDataAdapter(sSQL, m_oDB.Connection)
         m_oCB = New OleDbCommandBuilder(m_oDA)
         m_oDS = New OleDbDataSet()
         m_oDA.Fill(m_oDS)

      End Sub

      Public Function GetRow() As DataRow

         If m_oDS.Tables(0).Rows.Count > 0 Then
            Return m_oDS.Tables(0).Rows(0)
         Else
            Return m_oDS.Tables(0).NewRow()
         End If

      End Function

      Protected Sub SaveRow(ByVal oDR As DataRow)

         Dim oDC As DataColumn

         If m_oDS.Tables(0).Rows.Count = 0 Then
            m_oDS.Tables(0).Rows.Add(oDR)
            Exit Sub
         End If

         m_oDS.Tables(0).Rows(0).BeginEdit()
         For Each oDC In m_oDS.Tables(0).Columns
            m_oDS.Tables(0).Rows(0).Item(oDC) = oDR.Item(oDC)
         Next

         m_oDS.Tables(0).Rows(0).EndEdit()

      End SUb

      Protected Sub AddError(ByVal sInput As String)

         If m_aErrors Is Nothing Then
            m_aErrors = New ArrayList()
         End If

         m_aErrors.Add(sInput)

      End Sub

      Protected Sub ClearErrors()

         If m_aErrors Is Nothing Then
            m_aErrors = New ArrayList()
         Else
            m_aErrors.Clear()
         End If

      End Sub

      Public Function ValidationError(Optional ByVal sHeader As String _
         = "The following errors were detected in your data:" & vbCrLf, _
         Optional ByVal sItemFormat As String = "- {0}" & vbCrLf, _
         Optional ByVal sFooter As String = "") As String

         Dim sMessage As New StringBuilder()
         Dim sError As String

         If m_aErrors.Count > 0 Then
            sMessage.Append(sHeader)
            For Each sError In m_aErrors
               sMessage.AppendFormat(sItemFormat, sError)
            Next
            sMessage.Append(sFooter)
            Return sMessage.ToString
         Else
            Return ""
         End If

      End Function

      Public readOnly Property ValidationErrors() As ArrayList

         Get
            Return m_aErrors
         End Get

      End Property

      Public ReadOnly Property IsValid() As Boolean

         Get
            Return(m_aErrors.Count = 0)
         End Get

      End Property

   End Class

End Namespace

And this is the batch file that I am using to try and compile the files....

echo off
if [%1] == [] goto noparam
if [%2] == [] goto noimports
vbc /debug /nologo /t:library /imports:%2.dll /r:System.dll,System.Xml.dll,System.Web.dll,System.Data.dll %1.vb
goto ok
:noimports
vbc /debug /nologo /t:library /r:System.dll,System.Xml.dll,System.Web.dll,System.Data.dll %1.vb
goto ok
:noparam
echo No file name was provided for compiling.
echo Use: Make FileName ImportFileName1,ImportFileName2,,
:ok
if errorlevel==0 echo %1.dll complied successfully.
ASKER CERTIFIED SOLUTION
Avatar of Justin_W
Justin_W

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
I have now renamed my namespaces to nsDatabase and nsBaseClass.

I am getting some different errors which are probably more to do with what else is inside the .vb files.

"Type 'OleDbdataAdapter' is not defined" etc.

I'll carry on tinkering and let you know how I get on.