页面一打开就报对象名无效,但是在数据库中有这个表,重新生成DLL覆盖后好了,不过隔段时间又有这个问题。SQL放到数据库中执行是对的

解决方案 »

  1.   

    这是页面aspx.cs的代码
    DataTable dtc = bll.GetBaseTypeByParid("1");
    这个BLL的代码
            /// <summary>
            /// 根据父ID获取基础数据
            /// </summary>
            /// <param name="parId">父ID</param>
            /// <returns></returns>
            public DataTable GetBaseTypeByParid(string parId)
            {
                return dal.GetBaseTypeByParid(parId);
            }
    这是DAL的代码
            /// <summary>
            /// 根据父ID获取基础数据
            /// </summary>
            /// <param name="id">父ID</param>
            /// <returns></returns>
            public DataTable GetBaseTypeByParid(string parId)
            {
                string sql = string.Format("select ID,TypeName from DX_BaseType where ParID={0} and Flag=1", parId);
                DataTable dt = sp.ExecuteDataSet(sql).Tables[0];
                if (dt != null)
                    return dt;
                else
                    return null;
            }
      

  2.   

    你可以做个测试,把sql语句打印出来(保存到txt或其它文件中),然后在数据库中执行看看。以我的经验肯定是程序的不严密造成此类的错误。
      

  3.   

    报的错是对象名无效,这说明在SQL执行时数据库中没有这个对象,但是我把SQL放到数据库中执行时没有错误的。数据库连接字符串也是对的,而且我把DLL重新生成后又好了