|
-
Apr 10th, 2009, 06:26 AM
#1
Thread Starter
Junior Member
[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
-
Apr 10th, 2009, 07:41 AM
#2
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
-
Apr 10th, 2009, 07:44 AM
#3
Thread Starter
Junior Member
Re: access a DataTable which created at runtime
 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
Last edited by iRoN_RoCK; Apr 10th, 2009 at 07:49 AM.
-
Apr 10th, 2009, 07:51 AM
#4
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
-
Apr 10th, 2009, 07:59 AM
#5
Thread Starter
Junior Member
Re: access a DataTable which created at runtime
 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? 
Code:
Dim myQuery = From Player In DtPlayers _
Where Player.Item("Nationality").ToString = "Turkey" _
Select Player
TestGridView.DataSource = myQuery
-
Apr 11th, 2009, 02:10 PM
#6
Thread Starter
Junior Member
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
Tags for this Thread
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|