2

I'm planning to utilize the global import for System.Data package. After I added the

<%@ Import Namespace="System.Data" %> 

in the markup of global.asax

In one of my class I removed 'Using System.Data' on top of the code. I built the global.asax and the class.

But instead of built successful, I received error

The name 'CommandType' does not exist in the current context.

GEOCHET
  • 21,119
  • 15
  • 74
  • 98
danial
  • 607
  • 2
  • 12
  • 20

2 Answers2

2

I think that you misunderstand what global.asax does.

It doesn't provide for global Import/Using statements.

Read up on it here and even better a Stackoverflow answer here

Global.asax allows you to handle application/session lifecyle events.

You will need to include your Import Namespace in the files that you are using calls to the System.Data namespace

Community
  • 1
  • 1
Nathan Koop
  • 24,803
  • 25
  • 90
  • 125
1

I think you might need to import the System.Data.SqlClient namespace too, assuming that's a command object it's failing on.

EDIT

If you want certain namespaces available to all pages, try adding them in the web.config instead:

<pages>
    <namespaces>
        <add namespace="System.IO" />
        <add namespace="ProjectName.Classes" />
    </namespaces>
</pages>
James Johnson
  • 45,496
  • 8
  • 73
  • 110