gpt4 book ai didi

c# - 当前上下文中不存在名称 'ConfigurationManager'

转载 作者:行者123 更新时间:2023-11-30 18:55:06 32 4
gpt4 key购买 nike

大家好,我收到以下错误:“名称‘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;
}

}
}

最佳答案

您是否添加了对 System.Configuration.dll 的引用?

关于c# - 当前上下文中不存在名称 'ConfigurationManager',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10072234/

32 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com