Home All Groups Group Topic Archive Search About

Wierdness with "Imports" statement

Author
16 Dec 2005 12:53 AM
danthman
Can someone tell me why the following VB.NET code doesn't work?

-----
Imports System.Data.SqlClient

Partial Class PageHeader

    Inherits System.Web.UI.UserControl

    Public ConnectionObjG As SqlConnection = New SqlConnection()
    Public AdapterObjG As SqlDataAdapter = New SqlDataAdapter()

    ...
-----

I get the following errors:
    Type 'SqlConnection'  is not defined.
    Type 'SqlDataAdapter'  is not defined.

The wierd part is that I get the squiggly "you did something wrong"
underlines after "New" but not after "As". If you don't have Visual
Studio .NET, the squiggly underlines shows where the errors are (like
the spellchecker in MS Word).

Even more strange: If I put the following code in my web.config file, I
get no errors at all.

-----
    <add namespace="System.Data.SqlClient" />
-----

Any idea what's going on here? Why is Import not importing?

Thanks,

-Dan

Author
16 Dec 2005 1:08 AM
KJ
OK, here's a dumb question: did you add a project reference to
System.Data?
Author
16 Dec 2005 1:19 AM
danthman
Yes. I have that in my web.config file. I also just tried adding an
"Imports System.Data" statement to the code module, but I still get the
same error.

Another thing I just tried:

-----
Imports System.Data.SqlClient

Partial Class PageHeader

    Inherits System.Web.UI.UserControl

    Public ConnectionObjG As SqlConnection = New
SqlClient.SqlConnection()
    Public AdapterObjG As SqlDataAdapter = New
SqlClient.SqlDataAdapter()
    ....
-----

No errors. Why?

Isn't it strange that the only the second reference in each case needs
the "SqlClient" prefix?

Thx,

-Dan

AddThis Social Bookmark Button