System.outofmemoryException同时显示从datatable到datagrid C#WPF的数据 [英] System.outofmemoryexception while displaying data from datatable to datagrid C# WPF

查看:296
本文介绍了System.outofmemoryException同时显示从datatable到datagrid C#WPF的数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试将数据从DataTable显示到Datagrid,但DataTable包含超过2万行,因此它提供了System.OutOfMemoryException。并且我无法显示数据和应用程序停止工作。



请帮助我解决

I am trying to display data from DataTable to Datagrid but DataTable contains more than 2 lakhs rows so it gives System.OutOfMemoryException. And I am not able to display data and application stop working.

Plese help me to resolve

System.OutOfMemoryException

这个问题。



我尝试了什么:



this issue.

What I have tried:

private void newBtn_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                if (txtDayfind.Text == "" || txtDatefind.Text == "" || txtTimefind.Text == "" || txtLatfind.Text == "" || txtLongfind.Text == "" || txtAddressfind.Text == "" || txtaccuracy.Text == "" || txtTypefind.Text == "")
                {
                    Button button = sender as Button;
                    string content = button.Content.ToString();
                    foreach (DataTable table in dsr.Tables)
                    {
                        if (table.TableName == content)
                        {
                            dataGrid1.ItemsSource = table.DefaultView;
                            dtselect = table;
                        }
                    }
                }
                else
                {
                    dataGrid1.ItemsSource = dtselect.DefaultView;
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }

推荐答案

猜测 - 这就是没有任何访问权限的机会 - 您正在向网格中加载太多,太多的行。使用调试器,找出您要设置的表数以及每个表中的行数。



然后想想那个面对那么多行的穷人。要他找到他需要的信息需要多长时间?分页,搜索,过滤。不要把它扔到他身上然后走开!



你为什么要依次装载所有桌子呢?你要做的只是用下一个覆盖它,所以单独的最后一个表仍然是......
At a guess - and that's all it can be without any access to your machine - you are loading far, far too many rows into your grid. Use the debugger, find out how many tables you are setting, and how many rows in each table.

Then think of the poor user, faced with that many rows. How long is it going to take him to find the info he needs? Page it, search it, filter it. don;t just dump it on him and walk away!

And why are you loading all tables in turn in anyway? All you do is overwrite it with the next so the last table alone remains...


这篇关于System.outofmemoryException同时显示从datatable到datagrid C#WPF的数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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