gpt4 book ai didi

c# - 自定义网格 LINQ to SQL

转载 作者:行者123 更新时间:2023-11-30 18:06:42 26 4
gpt4 key购买 nike

下面是我自定义的控件网格:

public partial class LinqGrid : UserControl
{
object tmpDataTable = new object();
public LinqGrid()
{
InitializeComponent();
}
public void Bind<T>(System.Data.Linq.Table<T> listSource) where T : class
{
Project.dbClassesDataContext dbc = new Project.dbClassesDataContext();
tmpDataTable = listSource;
var query = (from c in listSource select c);
dgvRecords.DataSource = query.Take(10).ToList();
}
private void btnNext_Click(object sender, EventArgs e)
{
// now what do I have to do here if I want next 10 records? I mean how to retrieve tmpDataTable object here? I can't find the type of variable.
}
}

最佳答案

如下定义你的类:

public partial class LinqGrid<T> : UserControl where T : class, new()
{
System.Data.Linq.Table<T> tmpDataTable;
public LinqGrid()
{
InitializeComponent();
}
public void Bind(System.Data.Linq.Table<T> listSource)
{
Project.dbClassesDataContext dbc = new Project.dbClassesDataContext();
tmpDataTable = listSource;
var query = (from c in listSource select c);
dgvRecords.DataSource = query.Take(10).ToList();
}
private void btnNext_Click(object sender, EventArgs e)
{
tmpDataTable.Skip(10).Take(10); ....
}
}

关于c# - 自定义网格 LINQ to SQL,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4573115/

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