473,396 Members | 1,990 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,396 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 15754
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...
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...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.