Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / Languages / C# / July 2007

Tip: Looking for answers? Try searching our database.

DataTable.Select problem <need suggestions>

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Jeff - 20 Jul 2007 07:56 GMT
.NET 2.0

I'm working on a  .NET 2.0 project which are using a DataSet for all
communication with the database.

Here is the problem:
I want to search a table based on a matching criteria (I call it
"criteriaA"). This result can give me multiple rows. For each of these rows
in the result, I need to perform another test to determine if other rows
also have this criteria...

So it's 2 selects: first select gives some rows, Each row contains a value
("criteriaB") which I need to perform another select on: select all records
matching criteriaB but are different from criteriaA

This could easly be done in a stored procedure, but we are not using that in
this project.

The DataSet we are using contains the DataTable which have the data I want
to select from.

I'm thinking about selecting the rows using the DataTable.Select method. The
first select add items into a generic list. And then I loop through the
generic list performing another select which again add items into another
generic list... Here I'll use 2 loops to create the result I want... But
there must be a better way doing this, or so I hope indeed

Any suggetions?
Manish Bafna - 20 Jul 2007 10:50 GMT
Hi,
You can specify multiple criteria in single statement.For example:
DataRow[] foundRows;
     DataTable myTable;
     myTable = ds.Tables["Orders"];
     // Setup Filter and Sort Criteria
     strExpr = "OrderDate >= '01.03.1998' AND OrderDate <= '31.03.1998'";
     strSort = "OrderDate DESC";
   
     // Use the Select method to find all rows matching the filter.
     foundRows = myTable.Select(strExpr, strSort);

Signature

Hope this helps.
Thanks and Regards.
Manish Bafna.
MCP and MCTS.

> ..NET 2.0
>
[quoted text clipped - 24 lines]
>
> Any suggetions?
Jeff - 20 Jul 2007 12:00 GMT
> Hi,
> You can specify multiple criteria in single statement.For example:
[quoted text clipped - 42 lines]
>>
>> Any suggetions?
Jeff - 20 Jul 2007 12:02 GMT
Thanks, but can I specify sub-selects in the DataTable.Select ?

> Hi,
> You can specify multiple criteria in single statement.For example:
[quoted text clipped - 42 lines]
>>
>> Any suggetions?
Nicholas Paldino [.NET/C# MVP] - 20 Jul 2007 20:16 GMT
Jeff,

   No, you can not.  What I am curious about is why you don't do this in a
stored procedure.  You said you aren't using it in this project, but this
seems like a compelling reason to me.

Signature

         - Nicholas Paldino [.NET/C# MVP]
         - mvp@spam.guard.caspershouse.com

> Thanks, but can I specify sub-selects in the DataTable.Select ?
>
[quoted text clipped - 45 lines]
>>>
>>> Any suggetions?

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.