473,597 Members | 2,328 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

using Directive Not Importing as Expected

I have the following three lines at the very top of a class file (prior to
the namespace declaration line).

using System;
using System.Data;
using System.Data.Sql Client;

Then, in a subsequent function in the same file I want to create a
connection by entering the following line:
SqlClient.SqlCo nnection cn = new
SqlClient.SqlCo nnection(Consta nts.ConnectionS tring);

However, as I start to enter that line, Intellisense does not recognize
SqlClient, and I must specify the fully qualified namespace hierarchy as
follows:

System.Data.Sql Client.SqlConne ction cn = new
System.Data.Sql Client.SqlConne ction(Constants .ConnectionStri ng);

I thought that specifying 'using System.Data;' and 'using
System.Data.Sql Client' would be enough to import those namespaces. What am I
missing?

Thanks,

Jeff
Nov 15 '05 #1
2 2463
> SqlClient.SqlCo nnection cn = new
SqlClient.SqlCo nnection(Consta nts.ConnectionS tring);


There's no need to type SqlClient. Try:
SqlConnection cn = new SqlConnection(C onstants.Connec tionString);

--
Mickey Williams
Author, "Microsoft Visual C# .NET Core Reference", MS Press
www.servergeek.com

Nov 15 '05 #2
"Jeff S" <Je******@asdf. com> wrote in message news:eO******** ******@TK2MSFTN GP10.phx.gbl...

I have the following three lines at the very top of a class file (prior to
the namespace declaration line).

using System;
using System.Data;
using System.Data.Sql Client;

Then, in a subsequent function in the same file I want to create a
connection by entering the following line:
SqlClient.SqlCo nnection cn = new
SqlClient.SqlCo nnection(Consta nts.ConnectionS tring);

However, as I start to enter that line, Intellisense does not recognize
SqlClient, and I must specify the fully qualified namespace hierarchy as
follows:

System.Data.Sql Client.SqlConne ction cn = new
System.Data.Sql Client.SqlConne ction(Constants .ConnectionStri ng);

I thought that specifying 'using System.Data;' and 'using
System.Data.Sql Client' would be enough to import those namespaces. What am I
missing?


Short answer: just write SqlConnection.

Long answer: unlike C++, in C# only unqualified names (without '.') are searched
in imported namespaces. Qualified names must always start from root. There is no such
thing as "partially qualified name".

Ivan
Nov 15 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
2903
by: Dennis Hore | last post by:
I'm trying to install Nick Patavalis' ppgplot package on Mac OS X 10.3 with python 2.3. I first sent this message to Nick, but he said he doesn't have any experience with the Mac platform. after installing using python setup.py install (using Numeric; no error messages), and then in python trying >>> import ppgplot i get:
13
141229
by: Squid Seven | last post by:
This is just bizarre. for the following snippet of code: #include <string> using std::string; I get the error message:
5
1599
by: Davíð Þórisson | last post by:
I've never understood fully, why do I have to td eg: using system; using system.data; I would have thought that the top line imports system and all of its submembers, including data??
12
2556
by: Charlie King | last post by:
As I understand it, the use of FIR* to replace heading tags with images in visually enabled CSS browsers is now frowned upon on the basis that some screen readers will *nor* read back text that is marked up by CSS to be invisible or hidden. So... If I want to replace headings with images (because my client wants to use his specific font for headings where possible), what's the best way to do it?
13
2778
by: rincewind | last post by:
I remember reading an article (was it Herb Sutter's?) that recommended avoiding using directives. While I quite understand this recommendation for headers, what's wrong in using directive in .cpp files?
3
6222
by: Donald Grove | last post by:
I need to get data from a table in .dbf format. I try importing it, but get "external table not in expected format". So I tried this VB code to see if I could get at my records with ADO (which I am very new to) " With cnn1 ..Provider = "microsoft.jet.oledb.4.0" ..Open "dBase
3
1910
by: Wayne Shu | last post by:
When I read the chapter of the namespace of the book C++ Primer(3e). It explain the using directive as follow: "A using directive makes the namespace member names visible as if they were declared outside the namespace at the location where the namespace definition is located." I have some doubt about the using directives for the nested namespace, so I wrote a program to test it, #include <iostream>
7
1623
by: =?Utf-8?B?QmVu?= | last post by:
Hi, I sometimes see code where the 'using' statements at the top of the file are located before the namespace declaration, and sometimes they are located inside it. For example: using System; using System.Collections;
3
5156
by: HistoricVFP | last post by:
Hello, I’ve been given the task of importing .dbf files from a very old version of Visual FoxPro (version 2.1) into Access (2003). When I import the data straight to Access it errors with: External table is not in the expected format. (Error 3274) I’ve tried the following but it did not work: “To import data from a FoxPro database, use the Microsoft Visual FoxPro ODBC driver. To do so, follow these steps: 1. Click Start, and then...
0
7962
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
7884
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8380
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
8258
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
5844
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
3880
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
3921
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
1493
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
1229
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.