1 using System;
2 using System.Collections;
3 using System.Collections.Generic;
4 using System.Linq;
5 using System.Web;
6 using System.Data;
7 using System.Data.Sql;
8 using System.Data.SqlClient;
9 using System.Configuration;
10 using System.Web.Security;
11 using System.Web.UI;
12
13 namespace test
14 {
15 public class operater
16 {
17 string strConn = ConfigurationManager.ConnectionStrings["ucssex_conn"].ConnectionString;
18 SqlConnection conn = new SqlConnection(strConn);
19
20 }
21 }
22
SqlConnection conn = new SqlConnection(strConn)这句会报错,提示找不strConn,为什么呢?
public class operater
{
public operater()
{
string strConn = ConfigurationManager.ConnectionStrings["ucssex_conn"].ConnectionString;
SqlConnection conn = new SqlConnection(strConn);
}
}