本文介绍了DataGridView使用LINQ安装程序不显示任何内容-为什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好,

在我当前的项目中,我使用VS2008和c#将LINQ to SQL与SQLite数据库一起使用.我想要一个表单来显示表的内容,因此设置一个DataGridView来做到这一点.不幸的是,我无法显示任何内容-DGV保持空白.

我看过的所有文章都建议执行以下操作,尽管也可以使用BindingSource进行以下操作:

Hi Folks,

In my current project I''m using LINQ to SQL with an SQLite database, using VS2008 and c#. I wanted a form to display the contents of a table, so set up a DataGridView to do that. Unfortunately I can''t get anything displayed - the DGV remains blank.

All the articles I''ve seen suggest the following should work, though it can also be done with a BindingSource:

db = new RWInfoDB(dbConnection);
var rwInfoTableQuery = from d in db.GetTable<RWInfoTable>() orderby d.Id select d;
pkgView.Show();
int c = rwInfoTableQuery.Count();
pkgView.dataGrid.DataSource = rwInfoTableQuery;



其中RWInfoDB是我的DataContext派生的类,dbConnection返回一个预装的SQLite连接对象,pkgView是DGV处于打开状态的形式,并且"int c"行仅证明该查询有效.
在运行时检查DGV对象将显示具有可见数据的DataSource成员-我可以看到其中的行-但是DGV的列和行"中为0-好像它甚至都没有查看DataSource.

[我从设置数据源后调用Show()开始,但是将其移动以查看是否有帮助]

DGV中是否有一些属性可以阻止它以这种方式工作?

有什么想法吗?

Ruth



Where RWInfoDB is my DataContext-derived class, dbConnection returns a pre-canned SQLite connection object, pkgView is the form the DGV is on, and the "int c" line just proves the query works.

Inspecting the DGV object at runtime shows a DataSource member with visible data - I can see the rows in there - and yet the DGV has 0 in Columns and Rows - as if it hasn''t even looked at the DataSource.

[I started with Show() called after setting DataSource, but moved it to see if that would help]

Are there properties in the DGV that could stop it working in this way?

Any thoughts?

Ruth

推荐答案

Using (Mydatacontext mydc = new Mydatacontext ())
{
    List<mytable> rows = mydc.mytableresults.tolist();
    mydatasource= rows;
}
</mytable>


另一个选择是创建一个存储过程并以与上述相同的方式读取结果以填充网格.当查询变得更加复杂时,此方法会更好地工作


Another option would be to create a stored procedure and read the results in the same way as above to populate your grid. this method works much better when your queries become more complex



这篇关于DataGridView使用LINQ安装程序不显示任何内容-为什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-05 13:42