[RESOLVED] access a DataTable which created at runtime
Hello guys,
I created a Datatable at runtime, added data to it succesfully but now i cant access it. For example, I can't filter by nationality
Code:
Public DtPlayers As New DataTable("PlayerNames")
Private Sub frmMain_Load(...)
Do Until cnt=playerCount
...
DtPlayers.Rows.Add(New Object() {cnt, PlID, PlName, vbNullString, _
PlAge, PlNationality, PlHeight, PlWeight, PlPosition})
cnt=cnt+1
Loop
end sub
Private Sub TestGrid_ColumnHeaderMouseClick(...)
Dim myQuery = From Player In DtPlayers _
Where _(what should i add here?)_ = "Turkey" _
Select Player
End Sub
Thanks in advance,
iRoN_RoCK
Re: access a DataTable which created at runtime
That's because it's not a typed datatable.... so LINQ has no way of knowing what fields are in the datatable. But... that just means you don't get the nicety of intellisense... It's still possible to extract field values....
I think this is what you are looking for:
Code:
Where DtPlayers.Item("stuff your nationality field name here").ToString = "Turkey" _
-tg
Re: access a DataTable which created at runtime
Quote:
Originally Posted by
techgnome
That's because it's not a typed datatable.... so LINQ has no way of knowing what fields are in the datatable. But... that just means you don't get the nicety of intellisense... It's still possible to extract field values....
I think this is what you are looking for:
Code:
Where DtPlayers.Item("Nationality").ToString = "Turkey" _
-tg
'Item' is not a member of 'System.Data.DataTable' it said
Re: access a DataTable which created at runtime
Try Player instead of DtPlayers .... sorry... I'm used to typed Datatables, so I'm not used to this.... if that still doesn't work... try this:
Code:
Where (function(s) s.Item("stuff your nationality field name here").ToString = "Turkey") _
-tg
Re: access a DataTable which created at runtime
Quote:
Originally Posted by
techgnome
Try Player instead of DtPlayers .... sorry... I'm used to typed Datatables, so I'm not used to this.... if that still doesn't work... try this:
Code:
Where (function(s) s.Item("stuff your nationality field name here").ToString = "Turkey") _
-tg
this one was ok but it just cleared all rows from datagridview. what did i do wrong? :confused:
Code:
Dim myQuery = From Player In DtPlayers _
Where Player.Item("Nationality").ToString = "Turkey" _
Select Player
TestGridView.DataSource = myQuery
Re: access a DataTable which created at runtime
This one works. Thanks for your posts anyway:)
Code:
Dim dv = New DataView(DbPlayers)
dv.RowFilter = "Nationality = 'Turkey'"
TestGridView.DataSource = dv