Wierdness with "Imports" statement

D

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
 
D

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
 

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

Members online

Forum statistics

Threads
473,755
Messages
2,569,537
Members
45,020
Latest member
GenesisGai

Latest Threads

Top