Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/macos/10.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 获取ArgumentException=>;无法创建字段问题的子列表_C# - Fatal编程技术网

C# 获取ArgumentException=>;无法创建字段问题的子列表

C# 获取ArgumentException=>;无法创建字段问题的子列表,c#,C#,这是我的Datagridview分页代码,为什么我无法创建字段问题的ArgumentException未处理子列表。在这行代码中This.dataGridView1.DataSource=GetCurrentRecords(1,con)。我哪里做错了 public partial class ShowEngClgList : Form { OleDbConnection con = null; private OleDbCommand cmd1;

这是我的Datagridview分页代码,为什么我无法创建字段问题的ArgumentException未处理子列表。在这行代码中
This.dataGridView1.DataSource=GetCurrentRecords(1,con)。我哪里做错了

public partial class ShowEngClgList : Form
    {
        OleDbConnection con = null;
        private OleDbCommand cmd1;
        private OleDbCommand cmd2;
        private OleDbDataAdapter adp1 = null;
        DataSet ds;

        private int PageSize = 10;
        private int CurrentPageIndex = 1;
        private int TotalPage = 0; 
        public ShowEngClgList()
        {
            InitializeComponent();
            try
            {
                con = new OleDbConnection(@"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=db1.mdb");
                con.Open();
            }
            catch (Exception err)
            {

            }
            cmd1 = new OleDbCommand("Select * from Questions order by QID", con);
            ds = new DataSet();
            adp1 = new OleDbDataAdapter(cmd1);
            adp1.Fill(ds, "Questions");
            dataGridView1.DataSource = ds;
            dataGridView1.DataMember = "Questions";

            // WORK IN PAGING FOR DATAGRIDVIEW
            // Get total count of the pages; 
            this.CalculateTotalPages();
            this.dataGridView1.ReadOnly = true;
            // Load the first page of data; 
            this.dataGridView1.DataSource = GetCurrentRecords(1, con);//Getting exception at this line

        }
        private void ShowEngClgList_Load(object sender, EventArgs e)
        {

        }
        private void CalculateTotalPages()
        {
            int rowCount = ds.Tables["Questions"].Rows.Count;
            this.TotalPage = rowCount / PageSize;
            if (rowCount % PageSize > 0) // if remainder is more than  zero 
            {
                this.TotalPage += 1;
            }
        }
        private DataTable GetCurrentRecords(int page, OleDbConnection con)
        {
            DataTable dt = new DataTable();

            if (page == 1)
            {
                cmd2 = new OleDbCommand("Select TOP " + PageSize + " * from Questions ORDER BY QID", con);
            }
            else
            {
                int PreviouspageLimit = (page - 1) * PageSize;

                cmd2 = new OleDbCommand("Select TOP " + PageSize +
                    " * from Questions " +
                    "WHERE QID NOT IN " +
                "(Select TOP " + PreviouspageLimit + " QID from Questions ORDER BY QID) ", con); // +
                //"order by customerid", con);
            }
            try
            {
                // con.Open();
                this.adp1.SelectCommand = cmd2;
                this.adp1.Fill(dt);
            }
            finally
            {
                con.Close();
            }
            return dt;
        }
}

提前感谢您的帮助。

当我们通过数据集将自定义数据收集绑定到DataGridView时,只需设置数据源,无需设置datamember。 因此,删除这一行代码就解决了问题,代码工作正常

dataGridView1.DataMember = "EngColeges";

发布例外情况,您可以获得一些好的帮助!:)我已经发布了,这是无法创建字段问题的
子列表的例外。
,我在
dt
对象中没有得到任何内容,但它没有显示任何错误嗯。。。捕获任何异常而不进行处理是一种非常糟糕的做法。