日期:2014-05-17  浏览次数:20554 次

急!!!名为“XX”的列已属于此 DataTable,怎么解决?
求助各位,这个怎么解决,过几天就要交付了
页面报错:
名为“Admin_ID”的列已属于此 DataTable。

说明: 执行当前 Web 请求期间,出现未处理的异常。请检查堆栈跟踪信息,以了解有关该错误以及代码中导致错误的出处的详细信息。 

异常详细信息: System.Data.DuplicateNameException: 名为“Admin_ID”的列已属于此 DataTable。

源错误: 


行 41: SqlDataReader dr = admin.GetAdmins();
行 42: 
行 43: DataTable dt = SQLHelper.ConvertDrToDt(dr);
行 44: dt.Columns.Add("Admin_ID");//
行 45: dt.Columns.Add("AdminName");//

源文件: H:\NEWS_CHANEL\Backup\NEWS_CHANEL\Admin\AdminList.aspx.cs 行: 43 

堆栈跟踪: 


[DuplicateNameException: 名为“Admin_ID”的列已属于此 DataTable。]
  System.Data.DataColumnCollection.RegisterColumnName(String name, DataColumn column, DataTable table) +4841153
  System.Data.DataColumnCollection.BaseAdd(DataColumn column) +93
  System.Data.DataColumnCollection.AddAt(Int32 index, DataColumn column) +78
  System.Data.DataColumnCollection.Add(String columnName) +41
  NEWS_CHANEL.Admin.AdminList.data() in H:\NEWS_CHANEL\Backup\NEWS_CHANEL\Admin\AdminList.aspx.cs:43
  NEWS_CHANEL.Admin.AdminList.Page_Load(Object sender, EventArgs e) in H:\NEWS_CHANEL\Backup\NEWS_CHANEL\Admin\AdminList.aspx.cs:25
  System.Web.Util.CalliHelper.EventArgFunctionCaller(IntPtr fp, Object o, Object t, EventArgs e) +14
  System.Web.Util.CalliEventHandlerDelegateProxy.Callback(Object sender, EventArgs e) +35
  System.Web.UI.Control.OnLoad(EventArgs e) +99
  System.Web.UI.Control.LoadRecursive() +50
  System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +627

后台页面:
C# code

namespace NEWS_CHANEL.Admin
{
    public partial class AdminList : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                data();
                PageControl.ResetGridView(this.GridView1);
            }
        }
        private void data()
        {
            BLL.SysAdmin admin = new BLL.SysAdmin();
            SqlDataReader dr = admin.GetAdmins();
            DataTable dt = SQLHelper.ConvertDrToDt(dr);
            dt.Columns.Add("Admin_ID");
            dt.Columns.Add("AdminName");
            dt.Columns.Add("Role_ID");
            DAL.PageControl.GridViewDataBind(GridView1, dt);
        }
    }
}


SysAdmin类:
C# code

namespace BLL
{
    public class SysAdmin
    {
        //定义管理员组数值
        public static readonly int Superadmin = 0;
        public static readonly int Normaladmin = 1;
        public SqlDataReader GetAdmins()
        {
            SQLHelper sql = new SQLHelper();
            SqlDataReader dr = null;
            //执行存储过程
            try
            {
                sql.RunProc("Proc_Admins", out dr);
            }
            catch (Exception e)
            {
                throw e;
            }
            finally { }

            return dr;
        }
    }
}


PageControl类:
C# code

namespace DAL
{
    public class PageControl
    {
        private static string EmptyText = "没有相关数据!"; //数据为空时,Gridview显示提示

        public PageControl()
        {
 
        }
        /// <summary>
        /// 空数据时刷新页面正常显示表头
        /// </summary>
        /// <param name="gridview"&g