c# error

Posted on 2011-03-12
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

Question by:vbnetcoder
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
LVL 143

Expert Comment

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

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

Author Comment

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

Accepted Solution

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

Open in new window

SharePoint Admin?

Enable Your Employees To Focus On The Core With Intuitive Onscreen Guidance That is With You At The Moment of Need.

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.
LVL 52

Expert Comment

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

Open in new window


Author Closing Comment

ID: 35157651

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Performance in games development is paramount: every microsecond counts to be able to do everything in less than 33ms (aiming at 16ms). C# foreach statement is one of the worst performance killers, and here I explain why.
This article aims to explain the working of CircularLogArchiver. This tool was designed to solve the buildup of log file in cases where systems do not support circular logging or where circular logging is not enabled
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…
I've attached the XLSM Excel spreadsheet I used in the video and also text files containing the macros used below.…

738 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