Solved

c# error

Posted on 2011-03-12
6
189 Views
Last Modified: 2012-08-14
This line:

var conString = ConfigurationManager.ConnectionStrings["LocalSqlServer"];

gives me the error


The type or namespace name 'var' could not be found (are you missing a using directive or an assembly reference)

=====
This line


0
Comment
Question by:vbnetcoder
6 Comments
 
LVL 143

Expert Comment

by:Guy Hengel [angelIII / a3]
ID: 35118881
try:

string conString = ConfigurationManager.ConnectionStrings["LocalSqlServer"];
0
 

Author Comment

by:vbnetcoder
ID: 35118919
It tells me that I can't exlicitly convert it to string
0
 
LVL 143

Accepted Solution

by:
Guy Hengel [angelIII / a3] earned 500 total points
ID: 35118944
np:
string conString = ConfigurationManager.ConnectionStrings["LocalSqlServer"].ToString();

Open in new window

0
Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
LVL 33

Expert Comment

by:Todd Gerbert
ID: 35119795
Just to expand slightly...the C# keyword var was introduced with Visual Studio 2008, you won't be able to use it with earlier versions.
0
 
LVL 52

Expert Comment

by:Carl Tawn
ID: 35126690
And it should be:
string conString = ConfigurationManager.ConnectionStrings["LocalSqlServer"].ConnectionString;

Open in new window

0
 

Author Closing Comment

by:vbnetcoder
ID: 35157651
ty
0

Featured Post

Active Directory Webinar

We all know we need to protect and secure our privileges, but where to start? Join Experts Exchange and ManageEngine on Tuesday, April 11, 2017 10:00 AM PDT to learn how to track and secure privileged users in Active Directory.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Extention Methods in C# 3.0 by Ivo Stoykov C# 3.0 offers extension methods. They allow extending existing classes without changing the class's source code or relying on inheritance. These are static methods invoked as instance method. This…
This article describes a simple method to resize a control at runtime.  It includes ready-to-use source code and a complete sample demonstration application.  We'll also talk about C# Extension Methods. Introduction In one of my applications…

821 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question