Warning på namespace fra compiler (vbc - framework 4.0)
Jeg prøver, lidt for sjovt, at compile en vb-fil (test.vb) lavet i notepad, ved brug af den medfølgende compiler (vbc) i .net (framework 4.0), og bruger følgende kommando i en bat-fil "vbc /target:library c:\inetpub\wwwroot\Diverse\test.vb"Dette fungerer også fint ved nedenstående i vb-filen:
Imports Microsoft.VisualBasic
Public Class HW
Public Function HWO
return ("Hello World")
End Function
End Class
Men tilføjer jeg endnu en klasse til ovenstående i vb-filen, får jeg en warning på det importerede namespace (System.Data.OleDb), eller manglende importerede namspace:
Imports Microsoft.VisualBasic
Imports System.Data.OleDb
Public Class HW
Public Function HWO
return ("Hello World")
End Function
End Class
Public Class HW1
Public Function HWO1
Dim strConnection, strSQL as String
Dim objConnection as OledbConnection
Dim objCommand as OledbCommand
Dim dr as OledbDataReader
Dim sb1 As New Stringbuilder
strConnection = ("Provider=SQLNCLI11;Server=XXX\SQLEXPRESS;Database=XXX;Trusted_Connection=yes")
objConnection = New OledbConnection(strConnection)
objConnection.Open
strSQL = "Select * From testdb"
objCommand = New OleDbCommand(strSQL, objConnection)
dr = objCommand.ExecuteReader()
While (dr.Read())
sb1.Append (dr("id") & " " & dr("tekst") & "<br>")
End While
return (sb1.ToString)
dr.Close()
objConnection.Close()
strSQl = Nothing
dr = Nothing
objConnection = Nothing
objCommand = Nothing
End Function
End Class
Fejl fra compileren:
Microsoft (R) Visual Basic Compiler version 11.0.50709.17929
Copyright (c) Microsoft Corporation. All rights reserved.
c:\inetpub\wwwroot\Diverse\test.vb(3) : warning BC40056: Namespace or type speci
fied in the Imports 'System.Data.OleDb' doesn't contain any public member or can
not be found. Make sure the namespace or the type is defined and contains at lea
st one public member. Make sure the imported element name doesn't use any aliase
s.
Imports System.Data.OleDb
~~~~~~~~~~~~~~~~~
c:\inetpub\wwwroot\Diverse\test.vb(14) : error BC30002: Type 'OledbConnection' i
s not defined.
Dim objConnection as OledbConnection
~~~~~~~~~~~~~~~
c:\inetpub\wwwroot\Diverse\test.vb(15) : error BC30002: Type 'OledbCommand' is n
ot defined.
Dim objCommand as OledbCommand
~~~~~~~~~~~~
c:\inetpub\wwwroot\Diverse\test.vb(16) : error BC30002: Type 'OledbDataReader' i
s not defined.
Dim dr as OledbDataReader
~~~~~~~~~~~~~~~
c:\inetpub\wwwroot\Diverse\test.vb(17) : error BC30002: Type 'Stringbuilder' is
not defined.
Dim sb1 As New Stringbuilder
~~~~~~~~~~~~~
c:\inetpub\wwwroot\Diverse\test.vb(19) : error BC30002: Type 'OledbConnection' i
s not defined.
objConnection = New OledbConnection(strConnection)
~~~~~~~~~~~~~~~
c:\inetpub\wwwroot\Diverse\test.vb(24) : error BC30002: Type 'OleDbCommand' is n
ot defined.
objCommand = New OleDbCommand(strSQL, objConnection)
~~~~~~~~~~~~
Det virker lidt som om at der er problemer med at importere namespace, eller hvor i ligger fejlen?