gpt4 book ai didi

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

转载 作者:太空狗 更新时间:2023-10-29 23:23:23 25 4
gpt4 key购买 nike

这是我的 Datagridview 分页代码,为什么我得到这个 ArgumentException 未处理 无法创建字段问题的子列表。 在这行代码 this.dataGridView1.DataSource = GetCurrentRecords( 1,反对);。我哪里错了

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;
}
}

提前感谢您的帮助。

最佳答案

当我们通过数据集绑定(bind)自定义数据集合到DataGridView时,只需要设置数据源,不需要设置数据成员。因此,删除这行代码可以解决问题,并且代码可以正常工作。

dataGridView1.DataMember = "EngColeges";

关于c# - 获取 ArgumentException => 无法创建字段问题的子列表,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18072565/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com