using System.Configuration; this.cboxConn.Text.Trim() /// string getValue class DbConnection { private static string currentConnectionString = ConfigurationManager.ConnectionStrings["SalaryManager.Properties.Settings.severConnection"].ConnectionString; private static string loginConnectionStr = "数据库服务器"; public static string returnConnectionStr() { return loginConnectionStr; } public static string isServerConnection(string getValue ) { if (getValue == "数据库服务器") { currentConnectionString = ConfigurationManager.ConnectionStrings["SalaryManager.Properties.Settings.severConnection"].ConnectionString; } else { currentConnectionString = ConfigurationManager.ConnectionStrings["SalaryManager.Properties.Settings.localConnection"].ConnectionString; } loginConnectionStr = getValue; return currentConnectionString; } public static SqlConnection createConn() { SqlConnection thisConnection = new SqlConnection(currentConnectionString); return thisConnection; }