首页 新闻 会员 周边 捐助

的类型初始值设定项引发异常。

0
悬赏园豆:10 [已解决问题] 解决于 2012-04-17 00:47

配置文件:

<?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”的类型初始值设定项引发异常。

是怎么回事?请教高手

学(股)海无涯888888的主页 学(股)海无涯888888 | 初学一级 | 园豆:193
提问于:2012-04-16 22:55
< >
分享
最佳答案
0

建议看看这篇文章:类型初始值设定项引发异常

从你帖的代码中看不出错误,你断点调试一下,看看是哪里出错的

收获园豆:10
artwl | 专家六级 |园豆:16736 | 2012-04-16 23:04
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册