DataView

W

web1110

This is a rehash of a response question I made down below.

I am playing with the NorthWind database. I have created a DataSet and
loaded the Employees table into it. I have created a DataView on that
table.

Now, I am having trouble putting all the parts together to retrieve a single
row of that DataView. For instance, if I want to retrieve the row where
EmployeeId='2' and display the FirstName of that employee, what steps do I
need to perform? What I've tried keeps getting syntax errors or exceptions.

For instance, both

dataView1.RowFilter="EmployeeId != '2'";
dataView1.RowFilter="EmployeeId != 2"; // No single quotes

Gives me the error:

Cannot interpret token '!' at position 12.

Since the filter removes the rows that match the contition, I have to
negate the condition to get the data I want.

I'd appreciate some help.

Thanx,
Bill
 
W

web1110

Thanks again. Mind is on other things I guess. Anyway, additional details
on the steps would be very helpful.
 
W

web1110

As I play with this, I find that a table automatically has a defaultview
that can be used. Therefore, using a DataView does not appear to be
necessary. I think I am I making progress here.
 
C

Cor Ligthert

Bill,

You mean
dataView1.RowFilter = "EmployeeId='2'"
string MyFirstName = dataView1.Item[0]["FirstName"];


Cor
 
W

web1110

That's it. It was too simple to figure out except Item wasn't recognzed.
Had to use:

string MyFirstName=dataView1[0]["FirstName"].ToString();

Thank you much,
Bill
 

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