Imports System.Data or Imports System.Data.SqlClient?

Discussion in 'ASP .Net' started by Albert, Jul 9, 2008.

  1. Albert

    Albert Guest

    Hi,

    when do i need this: Imports System.Data
    and when this: Imports System.Data.SqlClient?

    More specifically, when i want to perform a select or update of a table
    using:
    connection = New SqlConnection(connectionstr)
    comd = New SqlCommand()

    do i need both?
    Thanks
    Albert
     
    Albert, Jul 9, 2008
    #1
    1. Advertisements

  2. Imports statement supplies references to all definitions in the namespace.
    So, if you use any classes from the System.Data namespaces, use Imports
    System.Data. In your example both SqlConnection and SqlCommand belong to the
    System.Data.SqlClient namespace, so use Imports System.Data.SqlClient.

    In fact, you can always use full names like
    connection = New System.Data.SqlClient.SqlConnection(connectionstr)

    In this case you don't need to use Imports statement.


    --
    Eliyahu Goldin,
    Software Developer
    Microsoft MVP [ASP.NET]
    http://msmvps.com/blogs/egoldin
    http://usableasp.net


    "Albert" <> wrote in message
    news:%...
    > Hi,
    >
    > when do i need this: Imports System.Data
    > and when this: Imports System.Data.SqlClient?
    >
    > More specifically, when i want to perform a select or update of a table
    > using:
    > connection = New SqlConnection(connectionstr)
    > comd = New SqlCommand()
    >
    > do i need both?
    > Thanks
    > Albert
    >
     
    Eliyahu Goldin, Jul 9, 2008
    #2
    1. Advertisements

  3. Albert

    Albert Guest

    Thanks,

    can you give me an example where i need imports.system.data, or with other
    words, what are the classes from System.Data namespaces?
    Thanks


    "Eliyahu Goldin" <> schreef in
    bericht news:%...
    > Imports statement supplies references to all definitions in the namespace.
    > So, if you use any classes from the System.Data namespaces, use Imports
    > System.Data. In your example both SqlConnection and SqlCommand belong to
    > the System.Data.SqlClient namespace, so use Imports System.Data.SqlClient.
    >
    > In fact, you can always use full names like
    > connection = New System.Data.SqlClient.SqlConnection(connectionstr)
    >
    > In this case you don't need to use Imports statement.
    >
    >
    > --
    > Eliyahu Goldin,
    > Software Developer
    > Microsoft MVP [ASP.NET]
    > http://msmvps.com/blogs/egoldin
    > http://usableasp.net
    >
    >
    > "Albert" <> wrote in message
    > news:%...
    >> Hi,
    >>
    >> when do i need this: Imports System.Data
    >> and when this: Imports System.Data.SqlClient?
    >>
    >> More specifically, when i want to perform a select or update of a table
    >> using:
    >> connection = New SqlConnection(connectionstr)
    >> comd = New SqlCommand()
    >>
    >> do i need both?
    >> Thanks
    >> Albert
    >>

    >
    >
     
    Albert, Jul 9, 2008
    #3
  4. Sure.

    http://msdn.microsoft.com/en-us/library/system.data.aspx

    --
    Eliyahu Goldin,
    Software Developer
    Microsoft MVP [ASP.NET]
    http://msmvps.com/blogs/egoldin
    http://usableasp.net


    "Albert" <> wrote in message
    news:%...
    > Thanks,
    >
    > can you give me an example where i need imports.system.data, or with other
    > words, what are the classes from System.Data namespaces?
    > Thanks
    >
    >
    > "Eliyahu Goldin" <> schreef in
    > bericht news:%...
    >> Imports statement supplies references to all definitions in the
    >> namespace. So, if you use any classes from the System.Data namespaces,
    >> use Imports System.Data. In your example both SqlConnection and
    >> SqlCommand belong to the System.Data.SqlClient namespace, so use Imports
    >> System.Data.SqlClient.
    >>
    >> In fact, you can always use full names like
    >> connection = New System.Data.SqlClient.SqlConnection(connectionstr)
    >>
    >> In this case you don't need to use Imports statement.
    >>
    >>
    >> --
    >> Eliyahu Goldin,
    >> Software Developer
    >> Microsoft MVP [ASP.NET]
    >> http://msmvps.com/blogs/egoldin
    >> http://usableasp.net
    >>
    >>
    >> "Albert" <> wrote in message
    >> news:%...
    >>> Hi,
    >>>
    >>> when do i need this: Imports System.Data
    >>> and when this: Imports System.Data.SqlClient?
    >>>
    >>> More specifically, when i want to perform a select or update of a table
    >>> using:
    >>> connection = New SqlConnection(connectionstr)
    >>> comd = New SqlCommand()
    >>>
    >>> do i need both?
    >>> Thanks
    >>> Albert
    >>>

    >>
    >>

    >
    >
     
    Eliyahu Goldin, Jul 10, 2008
    #4
  5. Albert

    Albert Guest

    Thanks

    "Eliyahu Goldin" <> schreef in
    bericht news:...
    > Sure.
    >
    > http://msdn.microsoft.com/en-us/library/system.data.aspx
    >
    > --
    > Eliyahu Goldin,
    > Software Developer
    > Microsoft MVP [ASP.NET]
    > http://msmvps.com/blogs/egoldin
    > http://usableasp.net
    >
    >
    > "Albert" <> wrote in message
    > news:%...
    >> Thanks,
    >>
    >> can you give me an example where i need imports.system.data, or with
    >> other words, what are the classes from System.Data namespaces?
    >> Thanks
    >>
    >>
    >> "Eliyahu Goldin" <> schreef in
    >> bericht news:%...
    >>> Imports statement supplies references to all definitions in the
    >>> namespace. So, if you use any classes from the System.Data namespaces,
    >>> use Imports System.Data. In your example both SqlConnection and
    >>> SqlCommand belong to the System.Data.SqlClient namespace, so use Imports
    >>> System.Data.SqlClient.
    >>>
    >>> In fact, you can always use full names like
    >>> connection = New System.Data.SqlClient.SqlConnection(connectionstr)
    >>>
    >>> In this case you don't need to use Imports statement.
    >>>
    >>>
    >>> --
    >>> Eliyahu Goldin,
    >>> Software Developer
    >>> Microsoft MVP [ASP.NET]
    >>> http://msmvps.com/blogs/egoldin
    >>> http://usableasp.net
    >>>
    >>>
    >>> "Albert" <> wrote in message
    >>> news:%...
    >>>> Hi,
    >>>>
    >>>> when do i need this: Imports System.Data
    >>>> and when this: Imports System.Data.SqlClient?
    >>>>
    >>>> More specifically, when i want to perform a select or update of a table
    >>>> using:
    >>>> connection = New SqlConnection(connectionstr)
    >>>> comd = New SqlCommand()
    >>>>
    >>>> do i need both?
    >>>> Thanks
    >>>> Albert
    >>>>
    >>>
    >>>

    >>
    >>

    >
    >
     
    Albert, Jul 10, 2008
    #5
    1. Advertisements

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. Bob of the West
    Replies:
    1
    Views:
    3,196
    William F. Robertson, Jr.
    May 17, 2004
  2. =?Utf-8?B?S2FseWFu?=
    Replies:
    2
    Views:
    1,535
    =?Utf-8?B?S2FseWFu?=
    Jun 18, 2004
  3. TN Bella
    Replies:
    2
    Views:
    2,601
    TN Bella
    Jun 20, 2004
  4. Kal
    Replies:
    1
    Views:
    9,845
    Kevin Spencer
    Jun 21, 2004
  5. Chris Langston
    Replies:
    3
    Views:
    11,955
    evilla
    Sep 12, 2006
  6. Stan
    Replies:
    0
    Views:
    767
  7. =?Utf-8?B?UGF0cmljay5PLklnZQ==?=

    System.Data.SqlClient.SqlException: problem!

    =?Utf-8?B?UGF0cmljay5PLklnZQ==?=, Sep 30, 2004, in forum: ASP .Net
    Replies:
    2
    Views:
    2,583
    =?Utf-8?B?UGF0cmljay5PLklnZQ==?=
    Sep 30, 2004
  8. egsdar
    Replies:
    0
    Views:
    1,715
    egsdar
    Dec 13, 2008
Loading...