473,378 Members | 1,388 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,378 software developers and data experts.

Dataview.RowFilter problem - displaying field value from first row


When I use the dataview.rowfilter and I try to display the field value of
the first row, the code doesn't seem to show the first row AFTER the
rowfilter.
This is my code:

DataView DataView_Filter = new DataView();
DataView_Filter.Table = DS_States.Tables["Table1"];
sFilter = "Emplcode = '123233'";
DataView_Filter.RowFilter = sFilter;
MessageBox.Show (DataView_Filter.Count.ToString()); //it displays 6
items, which is correct.
MessageBox.Show (DataView_Filter.Table.Rows[0]["Emplcode"].ToString());
//it displays the first item of the initial dataview, not the filtered
dataview

How can I display the first item of the filtered dataview? I assume there
must be some method that returns the array index since Rows[0] is not
necessarily the first row of the filtered dataview.

Jim
Nov 16 '05 #1
5 15745
Hi Jim,

Based on my understanding, you want to do the row filter through dataview
for your datatable.

After view your code, I find that your filter is correct, but you get the
filtered rows in an in-correct way.

After setting the RowFilter for DataView, you use DataView.Table property
to get the rows. If you view in MSDN, you will see that DataView.Table
property gets the source DataTable, which has nothing to do with filter(You
only filter the dataview not the underlying datatable). So you will get the
source datatable's first row.

Actually, you should do like this:

DataView dv_filter=new DataView();
dv_filter.Table=ds.Tables[0];
dv_filter.RowFilter ="Emplcode = '123233'";
MessageBox.Show(dv_filter[0].Row["Emplcode"]);

================================
Please apply my suggestion above and let me know if it helps resolve your
problem.

Thank you for your patience and cooperation. If you have any questions or
concerns, please feel free to post it in the group. I am standing by to be
of assistance.

Best regards,
Jeffrey Tan
Microsoft Online Partner Support
Get Secure! - www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.

Nov 16 '05 #2
Hi Jim,

Based on my understanding, you want to do the row filter through dataview
for your datatable.

After view your code, I find that your filter is correct, but you get the
filtered rows in an in-correct way.

After setting the RowFilter for DataView, you use DataView.Table property
to get the rows. If you view in MSDN, you will see that DataView.Table
property gets the source DataTable, which has nothing to do with filter(You
only filter the dataview not the underlying datatable). So you will get the
source datatable's first row.

Actually, you should do like this:

DataView dv_filter=new DataView();
dv_filter.Table=ds.Tables[0];
dv_filter.RowFilter ="Emplcode = '123233'";
MessageBox.Show(dv_filter[0].Row["Emplcode"]);

================================
Please apply my suggestion above and let me know if it helps resolve your
problem.

Thank you for your patience and cooperation. If you have any questions or
concerns, please feel free to post it in the group. I am standing by to be
of assistance.

Best regards,
Jeffrey Tan
Microsoft Online Partner Support
Get Secure! - www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.

Nov 16 '05 #3
Hi Jim,

Have you tried my suggestion? Is your problem resolved?

Please feel free to feedback. Thanks

Best regards,
Jeffrey Tan
Microsoft Online Partner Support
Get Secure! - www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.

Nov 16 '05 #4
Hi Jim,

Have you tried my suggestion? Is your problem resolved?

Please feel free to feedback. Thanks

Best regards,
Jeffrey Tan
Microsoft Online Partner Support
Get Secure! - www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.

Nov 16 '05 #5
Hi,
I am having this similiar problem and I tried the approach that you
mentioned but it didn't work.
Jim Heimer wrote:
When I use the dataview.rowfilter and I try to display the field value of the first row, the code doesn't seem to show the first row AFTER the
rowfilter.
This is my code:

DataView DataView_Filter = new DataView();
DataView_Filter.Table = DS_States.Tables["Table1"];
sFilter = "Emplcode = '123233'";
DataView_Filter.RowFilter = sFilter;
MessageBox.Show (DataView_Filter.Count.ToString()); //it displays 6 items, which is correct.
MessageBox.Show (DataView_Filter.Table.Rows[0]["Emplcode"].ToString()); //it displays the first item of the initial dataview, not the filtered dataview

How can I display the first item of the filtered dataview? I assume there must be some method that returns the array index since Rows[0] is not
necessarily the first row of the filtered dataview.

Jim


Nov 16 '05 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: Jim Heimer | last post by:
When I use the dataview.rowfilter and I try to display the field value of the first row, the code doesn't seem to show the first row AFTER the rowfilter. This is my code: DataView...
3
by: Siegfried Heintze | last post by:
I'm displaying information on job postings in various cities. For example, might have a dozen jobs in Atlanta GA and I decide, at run time, that I don't want to see them. How do I set my DataView...
8
by: Dave Hagerich | last post by:
I'm using a DataGrid with a DataSet and I'm trying to filter the data being displayed, using the following code as a test: DataView theView = new DataView(theDataSet.Tables); theView.RowFilter =...
10
by: Roy Lawson | last post by:
Can anyone explain the difference between RowStateFilter and RowFilter properties of the DataView objects in simple terms? I am going through a Transcender practice exam and just when I think I...
13
by: Steve | last post by:
I have a form with a dataset and a datagrid. I created a dataview on this dataset. When the user modifies the datagrid, I look up this record in the dataview to make sure it is unique. Here is...
14
by: Able | last post by:
Dear friends Dim myDataView as DataView = New DataView(dsData.Tables("tblCustomers")) myDataView.RowFilter = "City = 'London'" My question is how to loop through all rows in myDataView and...
1
by: =?Utf-8?B?VGVycmFuY2U=?= | last post by:
I've been having an issue with an application that keeps track of applications that a client has by state and print this information from my ..net app to an excel file. I'm using a dataview to...
1
by: AlexW | last post by:
Hi I am in the process of developing an inventory application in visual basic. I keep coming up against a problem with using the dataview.rowfilter property. Basically what happens is this: -a...
5
by: AlexW | last post by:
Hi I am in the process of developing an inventory application in visual basic. I keep coming up against a problem with using the dataview.rowfilter property. Basically what happens is this: -a...
3
by: =?Utf-8?B?cG1jZ3VpcmU=?= | last post by:
I have a dataset with 3 tables -- 2 Parent tables and 1 table that is a child table of both the parents. I create a dataview on the child table and set the rowfilter to a value which filters the...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.