本文介绍了linq查询到datatable,填充datagriview的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 29岁程序员,3月因学历无情被辞! 任何人都可以告诉我如何将加载linq查询放入datatable然后填充到datagridview? 我的代码如下: Dim dt 作为 新 DataTable ' '在DataTable中创建3个类型的列。 dt .Columns.Add( ConflictingPaper, GetType ( String )) dt.Columns.Add( Numberofstudents, GetType ( String )) dt .Columns.Add( AdminNo, GetType (字符串)) ' Dim query1 =(来自in dt3 Group Convert。 ToString(a.Field(Of Integer)(PaperNo))通过AdminNo =(a.Field(Of String)(AdminNo))进入组选择dt.LoadDataRow(New Object(){String.Join(: ,Group.ToArray()),Group.Count(),AdminNo},False))。ToList()。Count() Dim query = from r In dt3.AsEnumerable()让 adminno = r.Field( of String )( AdminNo)组r by adminno进入组选择 新 使用 {.AdminNo = adminno,.numberofstudents = Group.Count(),。conflictingpaper = 字符串。加入( :,Group。选择(功能(r)r.Field( of 整数)( paperno)。ToString()))} DataGridView3.AutoGenerateColumns = True DataGridView3.DataSource = query this: DataGridView3.AutoGenerateColumns = True DataGridView3.DataSource = query 不起作用。 我的数据没有加载。 有人帮我解决这个问题吗?谢谢! 从下面的评论中复制的其他信息 问题是: 我的数据没有加载。形式有点挂在那里。它不会填充任何东西。 希望你能帮我解决它。解决方案 DataGridView3.AutoGenerateColumns = True DataGridView3.DataSource = query.ToList() DataGridView3.DataBind() hi can anyone tell me how do i put load linq query into datatable then populate into datagridview?my codes are as follows:Dim dt As New DataTable '' Create 3 typed columns in the DataTable. dt.Columns.Add("ConflictingPaper", GetType(String)) dt.Columns.Add("Numberofstudents", GetType(String)) dt.Columns.Add("AdminNo", GetType(String)) 'Dim query1 = (From a In dt3 Group Convert.ToString(a.Field(Of Integer)("PaperNo")) By AdminNo = (a.Field(Of String)("AdminNo")) Into Group Select dt.LoadDataRow(New Object() {String.Join(":", Group.ToArray()), Group.Count(), AdminNo}, False)).ToList().Count() Dim query = From r In dt3.AsEnumerable() Let adminno = r.Field(Of String)("AdminNo") Group r By adminno Into Group Select New With {.AdminNo = adminno, .numberofstudents = Group.Count(), .conflictingpaper = String.Join(":", Group.Select(Function(r) r.Field(Of Integer)("paperno").ToString()))} DataGridView3.AutoGenerateColumns = True DataGridView3.DataSource = querythis: DataGridView3.AutoGenerateColumns = True DataGridView3.DataSource = querydoesn't work.My data are not loading out.anyone help me out with this? thanks!additional information copied from comment belowThe problem is:my data are not loading out. the form sort of hang there. it doesnt populate anything.hope you could help me out with it. 解决方案 DataGridView3.AutoGenerateColumns = True DataGridView3.DataSource = query.ToList() DataGridView3.DataBind() 这篇关于linq查询到datatable,填充datagriview的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 上岸,阿里云!
06-12 06:25