错误
在类,结构或接口成员声明中使用'无效标记
代码:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Configuration;
using System.Data;
using System.Data.SqlClient;
namespace BusinessLayer
{
class EmployeeBusinessLayer
{
String Connectionstring = ConfigurationManager.ConnectionStrings["DBConStr"].ConnectionString;
using(SqlConnection con = new SqlConnection()){
}
}
}
答案 0 :(得分:2)
您尝试在类范围内使用using
语句,该语句无效。请尝试以下方法:
public void YourMethod() {
string connStr = ConfigurationManager.ConnectionStrings["DBConStr"].ConnectionString.ToString();
using(SqlConnection connection = new SqlConnection()) {
//do something
}
}