Multiple conditions for DataView Filter

G

Guest

Is it possible to create a DataVew from a DataSet using a filter to matvch on
both first and last name?

dv = new DataView(ds.Tables["MediaData"],"LastName=Jones,FirstName=
Fred","",DataViewRowState.CurrentRows);

I've extracted this info using a DataView:
dv = new DataView(ds.Tables["MediaData"],"","LastName,
FirstName",DataViewRowState.CurrentRows);

and then a DataViewRow:
DataRowView[] drView = dv.FindRows(new object[]{lastName, firstName});

foreach (DataRowView drv in drView)
{
//process data
}

I just want to know if it can be done in one step instead of two.

TIA,
 
N

Nicholas Paldino [.NET/C# MVP]

Joe,

Absolutely. Just set the RowFilter property to "LastName = 'Jones' AND
FirstName = 'Fred'". I believe there is a constructor which takes this as
well.

Hope this helps.
 
G

Guest

Thanks. It does. Now that I have the DataView, how do I enumerate through
the rows to retrieve the value (so that I can display them, for example)?


Nicholas Paldino said:
Joe,

Absolutely. Just set the RowFilter property to "LastName = 'Jones' AND
FirstName = 'Fred'". I believe there is a constructor which takes this as
well.

Hope this helps.


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

Joe said:
Is it possible to create a DataVew from a DataSet using a filter to matvch
on
both first and last name?

dv = new DataView(ds.Tables["MediaData"],"LastName=Jones,FirstName=
Fred","",DataViewRowState.CurrentRows);

I've extracted this info using a DataView:
dv = new DataView(ds.Tables["MediaData"],"","LastName,
FirstName",DataViewRowState.CurrentRows);

and then a DataViewRow:
DataRowView[] drView = dv.FindRows(new object[]{lastName, firstName});

foreach (DataRowView drv in drView)
{
//process data
}

I just want to know if it can be done in one step instead of two.

TIA,
 

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