如何将数据表附加到datagridview [英] how to append datatable to datagridview

查看:60
本文介绍了如何将数据表附加到datagridview的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用sqlDataAdaptor(C#)将dataGridView与数据库的前20行绑定,现在在按钮点击事件上我想从数据库追加接下来的20条记录。请帮助紧急并提供示例代码。在此先感谢。

解决方案

您好,



每次点击数据库n行数不是一个好的做法。



请将整个表/查询绑定到DataTable并使用数据表与datagridview绑定。



以下代码是跳过DataTable(dt)中前10行并在此之后取10行的示例。 11行到21行。



 datagridView1.DataSource = dt.AsEnumerable()
.Skip( 10
。承担( 10
.CopyToDatatable();





您可以设置上一个和下一个按钮并使用此操作。



希望这有帮助。


i bound the dataGridView with first 20 rows from database using sqlDataAdaptor (C#) , now on button click event i want to append the next 20 records from database. Please help its urgent and give a sample code. Thanks in advance.

解决方案

Hello,

Everytime hitting the database for n number of rows is not a good practise.

Please bind the entire table/query to a DataTable and use the datatable to bind with your datagridview.

The below code is an example of skipping the first 10 rows in your DataTable (dt) and taking 10 rows after that. 11 row to 21.

datagridView1.DataSource = dt.AsEnumerable()
                                .Skip(10)
                                .Take(10)
                                .CopyToDatatable();



You can set a previous and next button and manipulate with this.

Hope this helps.


这篇关于如何将数据表附加到datagridview的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆