|
-
Jul 25th, 2014, 11:22 AM
#1
[RESOLVED] DataTable Filtering
Ok so have looked into the DataView and read that its not going to do what I want as I already have a DT populated but have a situation where I now need to filter it with a DISTINCT query and WHERE clause so using a dataview wont work. I dont want to requery the db just for this since its already in memory.
Ideas?
Thanks
VB/Office Guru™ (AKA: Gangsta Yoda™ ®)
I dont answer coding questions via PM. Please post a thread in the appropriate forum. 
Microsoft MVP 2006-2011
Office Development FAQ (C#, VB.NET, VB 6, VBA)
Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
If a post has helped you then Please Rate it! 
• Reps & Rating Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API Viewer utility • .NET API Viewer Utility •
System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6 
-
Jul 25th, 2014, 11:46 AM
#2
Re: DataTable Filtering
Looking at copying the datatable and doing a .DefaultView.ToTable(true, "chID").DefaultView.RowFilter = "chGrp = 'C'" but its giving an error that it cant find the column but it does exist in the dt.
Code:
DataTable dt = dsSTDDB.Tables["StandardCHP"].Copy();
DataView dv = dt.DefaultView.ToTable(true, "chID").DefaultView;
dv.RowFilter = "chGrp='C'";
Hmm ok well seems the distinct only pulls in the one field.
Last edited by RobDog888; Jul 25th, 2014 at 11:53 AM.
VB/Office Guru™ (AKA: Gangsta Yoda™ ®)
I dont answer coding questions via PM. Please post a thread in the appropriate forum. 
Microsoft MVP 2006-2011
Office Development FAQ (C#, VB.NET, VB 6, VBA)
Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
If a post has helped you then Please Rate it! 
• Reps & Rating Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API Viewer utility • .NET API Viewer Utility •
System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6 
-
Jul 25th, 2014, 12:02 PM
#3
Re: DataTable Filtering
?? What distinct? I don't see where you used distinct. Unless it was in the original SQL.
-tg
-
Jul 25th, 2014, 12:10 PM
#4
Re: DataTable Filtering
The "true" parameter is the distinct identifier in teh parameters
DataView dv = dt.DefaultView.ToTable(true, "chID").DefaultView;
I guess I could add the second column in hte list as I think it should still be distinct
VB/Office Guru™ (AKA: Gangsta Yoda™ ®)
I dont answer coding questions via PM. Please post a thread in the appropriate forum. 
Microsoft MVP 2006-2011
Office Development FAQ (C#, VB.NET, VB 6, VBA)
Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
If a post has helped you then Please Rate it! 
• Reps & Rating Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API Viewer utility • .NET API Viewer Utility •
System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6 
-
Jul 25th, 2014, 12:16 PM
#5
Re: DataTable Filtering
Got it with this.
Code:
DataTable dt = dsSTDDB.Tables["StandardCHP"].Copy();
DataView dv = dt.DefaultView.ToTable(true, "chID", "chGrp").DefaultView;
dv.RowFilter = "chGrp='C'";
VB/Office Guru™ (AKA: Gangsta Yoda™ ®)
I dont answer coding questions via PM. Please post a thread in the appropriate forum. 
Microsoft MVP 2006-2011
Office Development FAQ (C#, VB.NET, VB 6, VBA)
Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
If a post has helped you then Please Rate it! 
• Reps & Rating Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API Viewer utility • .NET API Viewer Utility •
System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6 
-
Jul 25th, 2014, 12:34 PM
#6
Re: [RESOLVED] DataTable Filtering
Ahhh... didn't realize the .ToTable worked like that.
-tg
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
|