日期:2014-05-18  浏览次数:21489 次

设计器必须创建类型“System.Data.Common.DbDataAdapter”的实例,但该类型已声明为抽象,因此设计器无法创建该类型的实例
设计器必须创建类型“System.Data.Common.DbDataAdapter”的实例,但该类型已声明为抽象,因此设计器无法创建该类型的实例。 
隐藏  

在 System.ComponentModel.Design.Serialization.CodeDomSerializerBase.Error(IDesignerSerializationManager manager, String exceptionText, String helpLink)
在 System.ComponentModel.Design.Serialization.TypeCodeDomSerializer.Deserialize(IDesignerSerializationManager manager, CodeTypeDeclaration declaration)
在 System.ComponentModel.Design.Serialization.CodeDomDesignerLoader.PerformLoad(IDesignerSerializationManager manager)
在 Microsoft.VisualStudio.Design.Serialization.CodeDom.VSCodeDomDesignerLoader.PerformLoad(IDesignerSerializationManager serializationManager)
在 System.ComponentModel.Design.Serialization.BasicDesignerLoader.BeginLoad(IDesignerLoaderHost host) 

C# code

using System;
using System.Collections.Generic;
using System.Text;
using System.Data;
using System.Data.Common;

namespace Components
{
    class DataReaderAdapter:DbDataAdapter
    {
        public int FillFromReader(DataTable dataTable, IDataReader dataReader)
        {
            return Fill(dataTable, dataReader);
        }

        protected override RowUpdatedEventArgs CreateRowUpdatedEvent(DataRow dataRow, IDbCommand command, StatementType statementType, DataTableMapping tableMapping)
        {
            return null;
        }

        protected override RowUpdatingEventArgs CreateRowUpdatingEvent(DataRow dataRow, IDbCommand command, StatementType statementType, DataTableMapping tableMapping)
        {
            return null;
        }

        protected override void OnRowUpdated(RowUpdatedEventArgs value)
        {
        }
        protected override void OnRowUpdating(RowUpdatingEventArgs value)
        {
        } 
    }
}

#region 将DataReader 转为 DataTable
        /// <summary>
        /// 将DataReader 转为 DataTable
        /// </summary>
        /// <param name="DataReader">DataReader</param>
        public static DataTable ConvertDataReaderToDataTable(SqlDataReader dataReader)
        {
            DataTable datatable = new DataTable();
            try
            {
                DataTable schemaTable = dataReader.GetSchemaTable();
                //int bun=schemaTable.Rows.Count;
                //DataColumn myDataColumn = new DataColumn();
                //for(int bui=0;bui<bun;bui++)
                //{

                //myDataColumn.DataType    = schemaTable.Rows[0].GetType();
                //myRow.GetType();
                //myDataColumn.ColumnName = schemaTable.Rows[0].ToString();


                //}
                //datatable.Columns.Add(myDataColumn);
                if (schemaTable != null)
                {
                    foreach (DataRow myRow in schemaTable.Rows)
                    {
                        DataColumn myDataColumn = new DataColumn();
                        myDataColumn.DataType = myRow.GetType();
                        myDataColumn.ColumnName = myRow[0].ToString();
                        datatable.Columns.Add(myDataColumn);
                    }

                }
                DataReader dra = new DataReader();
                dra.FillFromReader(datatable, dataReader);
                dra = null;
                dataReader.Close();

            }
            catch (Exception ex)
            {
                Error.Log(ex.ToString());
                throw new Exception("转换出错!", ex);
            }
            return datatable;
        }

        #endregion



请问怎么解决啊?

------解决方案--------------------
DbDataAdapter是抽象类,无法实例化

DbDataAdapter x=new SqlDataAdapter()