使用分页快速检索datagridview中的批量行. [英] fast retrieving bulk rows in datagridview using paging.

查看:64
本文介绍了使用分页快速检索datagridview中的批量行.的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

先生您好,

我正在开发c Sharp Windows应用程序.

我正在检索数据表中的数据,而我的数据表包含50000行.

并且我将此数据绑定到datagridview并使用按钮click一次显示20行以进行分页.

Hello sir,

i am developing c sharp windows application.

I am retriving data in datatable and my datatable contains 50000 rows.

and i am binding this data to datagridview and showing 20 rows at a time for paging using button click.

adapter = new SqlDataAdapter(command);
                       adapter.Fill(ds,startindex,20, "userinfo");

                       dt = ds.Tables["userinfo"];
                       gridData.DataSource = dt;





但是要花时间


这是我的代码,







but it takes times


this is my code,



try
                {
                    int currCat = Convert.ToInt32(cmbCategories.SelectedValue);
                    int  status = Convert.ToInt32(cmbAllStatus.SelectedValue);
                    int region = Convert.ToInt32(cmbAllRegion.SelectedValue);
                    string frmDate = Convert.ToString(dateTimePicker1.Value);
                    string toDate = Convert.ToString(dateTimePicker2.Value);
                    int user = Convert.ToInt32(cmbUsers.SelectedValue);
                    string isDateSelected = Convert.ToString(dateTimePicker1.Checked);
                    string isRemovesSelected = checkBoxRemoves.Checked.ToString();

                    MyConnect myCnn = new MyConnect();
                    String connString = myCnn.getConnect().ToString();

                    SqlConnection conn;
                    SqlDataAdapter adapter;
                    SqlCommand command;
                    DataSet ds;
                    DataTable dt = new DataTable();
                    conn = new SqlConnection(connString);
                    ds = new DataSet();
                    command = new SqlCommand();

                    conn.Open();
                    command.Connection = conn;

                    try
                    {
                        command.CommandType = CommandType.StoredProcedure;

                        command.CommandText = "GetDataForRetrieve";

                        command.Parameters.AddWithValue("@currCat", currCat);
                        command.Parameters.AddWithValue("@fromdate", frmDate);
                        command.Parameters.AddWithValue("@todate", toDate);
                        command.Parameters.AddWithValue("@user", user);
                        command.Parameters.AddWithValue("@region", region);
                        command.Parameters.AddWithValue("@status", status);
                        command.Parameters.AddWithValue("@isDateSelected", isDateSelected);
                        command.Parameters.AddWithValue("@isRemovesSelected", isRemovesSelected);


                        adapter = new SqlDataAdapter(command);
                        adapter.Fill(ds,startindex,20, "userinfo"); // here i am incrementing and showing  20 rows 

                       
                        dt = ds.Tables["userinfo"];
                        gridData.DataSource = dt;

                    }
                    catch (Exception ex1)
                    {
                    }
                    finally
                    {
                        conn.Close();
                    }
                }
                catch (Exception e1)
                {
                    MessageBox.Show(e1.Message.ToString());
                }


请提出快速检索的建议.
谢谢.


please give suggestion for fast retrive.
Thanks.

推荐答案

hi
请查看链接
http://msdn.microsoft.com/zh-cn/library/aa713421%28v=vs.71%29.aspx
hi
Please see the link
http://msdn.microsoft.com/en-us/library/aa713421%28v=vs.71%29.aspx


这篇关于使用分页快速检索datagridview中的批量行.的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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