473,699 Members | 2,184 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 2468
> 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
2910
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
141243
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
1602
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
2583
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
2783
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
6233
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
1916
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
1636
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
5173
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
8697
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
8622
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,...
1
8930
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8892
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...
0
5878
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4382
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
4634
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
2359
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2013
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.