Wrox Programmer Forums
|
ASP.NET 1.1 As of 10/6/2005, this forum is locked as part of the reorganization described here: http://p2p.wrox.com/topic.asp?TOPIC_ID=35394. No posts have been deleted. Open ongoing discussions from the last week have been moved to either ASP.NET 1.0 and 1.1 Beginners http://p2p.wrox.com/asp-net-1-0-1-1-basics-60/ or ASP.NET 1.0 and 1.1 Professional. http://p2p.wrox.com/forum.asp?FORUM_ID=50. See my sticky post inside for more.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ASP.NET 1.1 section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old December 15th, 2004, 06:07 PM
Authorized User
 
Join Date: Jul 2004
Posts: 21
Thanks: 0
Thanked 0 Times in 0 Posts
Default DataTable filtering technique

A question on DataTable filtering technique, i.e. when you use DataTable.Select(filterExpression, SortExpression). How to construct a filter expression string that specify the date within a range? Since this filter expression treat every column in the datatable as strings and compare them as strings, it wouldn't give correct result if you say " WHERE date >= 'Jun 30 2004' ". Anybody has any advices on this?

 
Old December 16th, 2004, 08:12 AM
Friend of Wrox
 
Join Date: Dec 2004
Posts: 307
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to Vadivel Send a message via Yahoo to Vadivel
Default

**********Code Snippet Starts Here**********
   DataTable objTable;
   objTable = DataSet1.Tables["TestTable"];

   string strExpression;
   string strSort;
   strExpression= "JoiningDate > '16/12/04'";
   strSort = "FirstName DESC";

   DataRow[] objResults;
   objResults= objTable.Select(strExpression, strSort);

   for(int i = 0; i < objResults.Length; i ++){
      Response.WriteLine(objResults[i][0]);
   }
**********Code Snippet Ends Here**********

Best Regards
Vadivel

MVP ASP/ASP.NET
http://vadivel.thinkingms.com
 
Old December 16th, 2004, 11:05 AM
Friend of Wrox
 
Join Date: Nov 2003
Posts: 1,348
Thanks: 0
Thanked 5 Times in 5 Posts
Default

I think a better idea would be to write a stored procedure and do you WHERE clause in it instead of filtering on the front end. I would be easier, and faster.

 
Old December 16th, 2004, 01:23 PM
Friend of Wrox
 
Join Date: Jul 2004
Posts: 623
Thanks: 0
Thanked 1 Time in 1 Post
Default

ybao,if your scenario is just filtering DataTable,I think DataView would be a better choice,
jbenson001,it could not be faster,connecting to datasource and executing sql queries and getting filtered rows is certainly slower than working on objects like DataView in disconnected environment.

_____________________________
Mehdi.
software engineering student.
Looking for a good job for summer 2005.
 
Old December 21st, 2004, 05:51 PM
planoie's Avatar
Friend of Wrox
 
Join Date: Aug 2003
Posts: 5,407
Thanks: 0
Thanked 16 Times in 16 Posts
Default

Mehdi,

The original poster never states that they are working with a truly disconnected dataset. We can't assume that the application is caching the dataset/datatable, nor should we. Regardless of any of this, the DataView class is operating on the same exact data as the DataTable.Select method, therefore provides no additional help to this scenario.

ybao-
If you construct a datatable with columns that are the correct data type (which they should be if you get them directly from the database) filtering and sorting *should* function as expected. Without testing, I can't categorically state that this is the correct answer, but I suspect that the DataTable column typing has something to do with the problem.





Similar Threads
Thread Thread Starter Forum Replies Last Post
Most efficient overriding technique jcsdeveloper C# 4 December 7th, 2005 04:18 PM
Swiping card technique?? rajanikrishna Pro VB Databases 1 December 18th, 2003 07:36 AM
The Technique for Scrolling Without Break [email protected] Flash (all versions) 0 August 11th, 2003 06:44 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.