当前位置: 代码迷 >> .NET面试 >> “DAL.DBHelper”的类型初始值设定项引发错误
  详细解决方案

“DAL.DBHelper”的类型初始值设定项引发错误

热度:74   发布时间:2016-05-02 02:00:47.0
“DAL.DBHelper”的类型初始值设定项引发异常。
(配置文件)
	<connectionStrings>
<add name="Conn" connectionString="Data Source=192.168.1.109;Initial Catalog=GuoHong;Persist Security Info=True;User ID=sa password=123"/>
</connectionStrings>

--------------------------------------------------
(DBHelper)

    public class DBHelper
    {
        public static string Conn = ConfigurationManager.ConnectionStrings["ConnStr"].ConnectionString;

        public static DataTable ExecuteDataTable(string sql,params SqlParameter[] para)
        {
            using(SqlConnection conn=new SqlConnection(Conn))
            {
                conn.Open();
                using(SqlCommand cmd=conn.CreateCommand())
                {
                    cmd.CommandText = sql;
                    cmd.Parameters.AddRange(para);
                    SqlDataAdapter ada = new SqlDataAdapter(cmd);
                    DataSet ds = new DataSet();
                    ada.Fill(ds);
                    return ds.Tables[0];
                }
            }
        }        
    }

-----------------------------------
(Default.aspx.cs)

    protected void Page_Load(object sender, EventArgs e)