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

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
 
E

Eliyahu Goldin

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
 
A

Albert

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
 
E

Eliyahu Goldin

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
 
A

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
 

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,774
Messages
2,569,596
Members
45,144
Latest member
KetoBaseReviews
Top