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

  • Thread starter Thread starter Albert
  • Start date Start date
A

Albert

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
 
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
 
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 said:
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 said:
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
 
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 said:
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 said:
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 said:
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
 
Thanks

Eliyahu Goldin said:
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 said:
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 said:
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


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
 
Back
Top