why "import namespace=" ..." if not necessary?

Discussion in 'ASP .Net' started by Chris, May 10, 2006.

  1. Chris

    Chris Guest

    Hi,

    1) In file test.aspx, i put:
    <%@ Page Language="VB" AutoEventWireup="false" CodeFile="test.aspx.vb"
    Inherits="test" %>
    <%@ import namespace="System.Data"%>
    <%@ import namespace="System.Data.OleDb"%>
    ....

    In file test.aspx.vb, i put:
    ....
    Dim oConnection As System.Data.OleDb.OleDbConnection
    ....
    No problem.It works.
    ----------------------------
    2) But if i put in test.aspx.vb:
    ....
    Dim oConnection As OleDbConnection
    ....
    I get the error: "type OleDbConnection is not defined"
    ---------------------------
    3) if i remove the import lines in test.aspx: and put this in test.aspx.vb:
    Dim oConnection As System.Data.OleDb.OleDbConnection
    .....

    it works too.

    So my question: why putting the import namespaces in test.aspx, because in
    any way, I have to use "Dim oConnection As
    System.Data.OleDb.OleDbConnection" instead of "Dim oConnection As
    OleDbConnection" ?

    Thanks
    Chris









    Why then the import in test.aspx?
     
    Chris, May 10, 2006
    #1
    1. Advertising

  2. Hi Chris,

    If you want to write the script in the same aspx page then the Import
    statement is required other wise it's not required.

    Hope this is clear.

    Balu

    "Chris" wrote:

    > Hi,
    >
    > 1) In file test.aspx, i put:
    > <%@ Page Language="VB" AutoEventWireup="false" CodeFile="test.aspx.vb"
    > Inherits="test" %>
    > <%@ import namespace="System.Data"%>
    > <%@ import namespace="System.Data.OleDb"%>
    > ....
    >
    > In file test.aspx.vb, i put:
    > ....
    > Dim oConnection As System.Data.OleDb.OleDbConnection
    > ....
    > No problem.It works.
    > ----------------------------
    > 2) But if i put in test.aspx.vb:
    > ....
    > Dim oConnection As OleDbConnection
    > ....
    > I get the error: "type OleDbConnection is not defined"
    > ---------------------------
    > 3) if i remove the import lines in test.aspx: and put this in test.aspx.vb:
    > Dim oConnection As System.Data.OleDb.OleDbConnection
    > .....
    >
    > it works too.
    >
    > So my question: why putting the import namespaces in test.aspx, because in
    > any way, I have to use "Dim oConnection As
    > System.Data.OleDb.OleDbConnection" instead of "Dim oConnection As
    > OleDbConnection" ?
    >
    > Thanks
    > Chris
    >
    >
    >
    >
    >
    >
    >
    >
    >
    > Why then the import in test.aspx?
    >
    >
    >
    >
    >
    >
    >
     
    =?Utf-8?B?YmFsdWNyaXM=?=, May 10, 2006
    #2
    1. Advertising

  3. Chris

    Chris Guest

    Hi Balu,

    Thanks for replying, but i still don't understand.

    In my first file (test.aspx)
    ----------------------------
    <%@ import namespace="System.Data"%>
    <%@ import namespace="System.Data.OleDb"%>

    In my second file (test.aspx.vb)
    --------------------------------
    Dim oConnection As OleDbConnection


    This doesn't work.

    I have to put:
    Dim oConnection As System.Data.OleDb.OleDbConnection
    But then, if i remove the import lines from test.aspx, it still works.

    So why putting those imports lines?



    "balucris" <> wrote in message
    news:...
    > Hi Chris,
    >
    > If you want to write the script in the same aspx page then the Import
    > statement is required other wise it's not required.
    >
    > Hope this is clear.
    >
    > Balu
    >
    > "Chris" wrote:
    >
    > > Hi,
    > >
    > > 1) In file test.aspx, i put:
    > > <%@ Page Language="VB" AutoEventWireup="false" CodeFile="test.aspx.vb"
    > > Inherits="test" %>
    > > <%@ import namespace="System.Data"%>
    > > <%@ import namespace="System.Data.OleDb"%>
    > > ....
    > >
    > > In file test.aspx.vb, i put:
    > > ....
    > > Dim oConnection As System.Data.OleDb.OleDbConnection
    > > ....
    > > No problem.It works.
    > > ----------------------------
    > > 2) But if i put in test.aspx.vb:
    > > ....
    > > Dim oConnection As OleDbConnection
    > > ....
    > > I get the error: "type OleDbConnection is not defined"
    > > ---------------------------
    > > 3) if i remove the import lines in test.aspx: and put this in

    test.aspx.vb:
    > > Dim oConnection As System.Data.OleDb.OleDbConnection
    > > .....
    > >
    > > it works too.
    > >
    > > So my question: why putting the import namespaces in test.aspx, because

    in
    > > any way, I have to use "Dim oConnection As
    > > System.Data.OleDb.OleDbConnection" instead of "Dim oConnection As
    > > OleDbConnection" ?
    > >
    > > Thanks
    > > Chris
    > >
    > >
    > >
    > >
    > >
    > >
    > >
    > >
    > >
    > > Why then the import in test.aspx?
    > >
    > >
    > >
    > >
    > >
    > >
    > >
     
    Chris, May 10, 2006
    #3
  4. Import the namespaces in the file where you use them. If you want to use
    the namespace in the vb file, import them there:

    Imports System.Data
    Imports System.Data.OleDb

    Chris wrote:
    > Hi Balu,
    >
    > Thanks for replying, but i still don't understand.
    >
    > In my first file (test.aspx)
    > ----------------------------
    > <%@ import namespace="System.Data"%>
    > <%@ import namespace="System.Data.OleDb"%>
    >
    > In my second file (test.aspx.vb)
    > --------------------------------
    > Dim oConnection As OleDbConnection
    >
    >
    > This doesn't work.
    >
    > I have to put:
    > Dim oConnection As System.Data.OleDb.OleDbConnection
    > But then, if i remove the import lines from test.aspx, it still works.
    >
    > So why putting those imports lines?
    >
    >
    >
    > "balucris" <> wrote in message
    > news:...
    >> Hi Chris,
    >>
    >> If you want to write the script in the same aspx page then the Import
    >> statement is required other wise it's not required.
    >>
    >> Hope this is clear.
    >>
    >> Balu
    >>
    >> "Chris" wrote:
    >>
    >>> Hi,
    >>>
    >>> 1) In file test.aspx, i put:
    >>> <%@ Page Language="VB" AutoEventWireup="false" CodeFile="test.aspx.vb"
    >>> Inherits="test" %>
    >>> <%@ import namespace="System.Data"%>
    >>> <%@ import namespace="System.Data.OleDb"%>
    >>> ....
    >>>
    >>> In file test.aspx.vb, i put:
    >>> ....
    >>> Dim oConnection As System.Data.OleDb.OleDbConnection
    >>> ....
    >>> No problem.It works.
    >>> ----------------------------
    >>> 2) But if i put in test.aspx.vb:
    >>> ....
    >>> Dim oConnection As OleDbConnection
    >>> ....
    >>> I get the error: "type OleDbConnection is not defined"
    >>> ---------------------------
    >>> 3) if i remove the import lines in test.aspx: and put this in

    > test.aspx.vb:
    >>> Dim oConnection As System.Data.OleDb.OleDbConnection
    >>> .....
    >>>
    >>> it works too.
    >>>
    >>> So my question: why putting the import namespaces in test.aspx, because

    > in
    >>> any way, I have to use "Dim oConnection As
    >>> System.Data.OleDb.OleDbConnection" instead of "Dim oConnection As
    >>> OleDbConnection" ?
    >>>
    >>> Thanks
    >>> Chris
    >>>
    >>>
    >>>
    >>>
    >>>
    >>>
    >>>
    >>>
    >>>
    >>> Why then the import in test.aspx?
    >>>
     
    =?ISO-8859-1?Q?G=F6ran_Andersson?=, May 10, 2006
    #4
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Nehmo Sergheyev

    Why is WWW necessary in some URLs?

    Nehmo Sergheyev, Dec 31, 2003, in forum: HTML
    Replies:
    27
    Views:
    13,701
    Toby A Inkster
    Jan 1, 2004
  2. alg

    Why casting necessary?

    alg, Jul 14, 2003, in forum: C++
    Replies:
    2
    Views:
    300
    David White
    Jul 15, 2003
  3. Mr. SweatyFinger

    why why why why why

    Mr. SweatyFinger, Nov 28, 2006, in forum: ASP .Net
    Replies:
    4
    Views:
    933
    Mark Rae
    Dec 21, 2006
  4. Mr. SweatyFinger
    Replies:
    2
    Views:
    2,128
    Smokey Grindel
    Dec 2, 2006
  5. psp
    Replies:
    7
    Views:
    326
    benben
    May 14, 2007
Loading...

Share This Page