2012-04-09 3 views
2

こんにちは、現在のコンテキストで、私は次のエラーを取得しています一人一人が存在しません:「名前 『のConfigurationManager』は現在のコンテキスト内に存在しない」を名「のConfigurationManager」は

// namespaces 
using System; 
using System.Collections.Generic; 
using System.ComponentModel; 
using System.Data; 
using System.Drawing; 
using System.Linq; 
using System.Text; 
using System.Windows.Forms; 
using System.Data.SqlClient; 
using System.Configuration; 
using System.IO; 

namespace Database1 
{ 
    public partial class Form1 : Form 
    { 
     public Form1() 
     { 
      InitializeComponent(); 
     } 
     public static string GetConnectionString(string strConnection) 
     { 
      //variable to hold our connection string for returning it 

      string strReturn = ""; 
      //check to see if the user provided a connection string name 
      //this is for if your application has more than one connection string 

      if (!string.IsNullOrEmpty(strConnection)) //a connection string name was   
      { 
       //get the connection string by the name provided 
       strReturn = ConfigurationManager.ConnectionStrings[strConnection].ConnectionString; 

      } 
      else //no connection string name was provided 
      { 
       //get the default connection string 
       strReturn = ConfigurationManager.ConnectionStrings["YourConnectionName"].ConnectionString; 
      } 
      //return the connection string to the calling method 
      return strReturn; 
     } 

    } 
} 

答えて

0

使用している.NET FrameworkとVisual Studioのバージョンはどれですか?

ConfigurationManagerは.NET 2以上でのみ使用できます。 .NET Framework 1.xおよびVisual Studio 2002/2003を使用している場合は、このクラスをまったく使用できません。

http://msdn.microsoft.com/en-us/library/system.configuration.configurationmanager.aspx

このページの一番上に「他のバージョン」リンクをクリックすると、それがサポートするすべてのバージョンが表示されます。

11

あなたが追加しましたSystem.Configuration.dllへの参照?あなたは右

をクリックして、追加参照]ボタンをクリックするとSystem.Configuration.dll

への参照を追加する必要が

+0

ありません[参照の追加]タブでこの参照を見つけることができません。 – user1312412

+0

メッセージは型や名前空間のようなものではないはずですが、この場合は 'ConfigurationManager'が見つかりませんか? – V4Vendetta

+0

どのバージョンのVisual Studioと.NET Frameworkを使用していますか? – Joshua

3

はあなたがする必要があります開いたポップアップがあり

で.NET]タブをクリックしますSystem.Configuration.dllファイルを見つけることができます

+0

いいえ、私はそれを試してみましたが、私はこのタブでSystem.Configuration.dllファイルを見つけることができません – user1312412

+0

あなたはそれを見つけることができない奇妙な?多分VS – V4Vendetta

+0

を再起動する必要がありますか.Netフレームワークを再インストールする必要があるかもしれませんか? – Pete

1

これはパスです:私はこの参照を追加し、私はなかった

C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.0\System.Configuration.dll 

また、あなたが:System:

C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.0\System.Configuration.Install.dll 

への参照を追加することができます(それが:)に役立ちます願っています)

関連する問題