配置文件:
<?xml version="1.0" encoding="utf-8" ?> <configuration>
<connectionStrings>
<add name="Strcon" connectionString="Data Sourse=.\SQLEXPRESS;Initial Catalog=Province_City;Integrated Security=True"/>
</connectionStrings>
</configuration>
DAL中sqlhelpe的:
public static readonly string Strcon = ConfigurationManager.ConnectionStrings["Strcon"].ConnectionString;
public static DataTable ExecuteDataTable(string cmdText, params SqlParameter[] parameters) { using (SqlConnection conn = new SqlConnection(Strcon)) { conn.Open(); using (SqlCommand cmd = conn.CreateCommand()) { cmd.CommandText = cmdText; cmd.Parameters.AddRange(parameters); using (SqlDataAdapter adapter = new SqlDataAdapter(cmd)) { DataTable dt = new DataTable(); adapter.Fill(dt); return dt; } } } }
DAL中类的
class Province_City { public static DataTable Getdata() { string sql = "select * from Province_City where ParentID=@id"; object i=0; return sqlhelper.ExecuteDataTable(sql,new SqlParameter("id",i)); } }
出现的问题是:
DAL.sqlhelper”的类型初始值设定项引发异常。
是怎么回事?请教高手
- 1 回答
- 0 关注
- 1245 浏览
添加回答
举报
0/150
提交
取消