DataTable.Select problem <need suggestions>

J

Jeff

..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?
 
G

Guest

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);
 
J

Jeff

Manish Bafna said:
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);

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



Jeff said:
..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?
 
J

Jeff

Thanks, but can I specify sub-selects in the DataTable.Select ?


Manish Bafna said:
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);

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



Jeff said:
..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?
 
N

Nicholas Paldino [.NET/C# MVP]

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.


--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)

Jeff said:
Thanks, but can I specify sub-selects in the DataTable.Select ?


Manish Bafna said:
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);

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



Jeff said:
..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?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top