Solved

Filter Datatable

Posted on 2013-06-07
8
289 Views
Last Modified: 2013-06-07
Hi,

I am trying to filter data table _title on its PK by passing titleid through a function. But it does not work.

Private Sub Fetchrecord(titleid As String)
       
            '_title.Select("TitleID = " + titleid)
            _title.DefaultView.RowFilter = "TitleID= '" + titleid.ToString() + "'"
                 
    End Sub
I tried both the above lines Still no luck

PS: I have tried all links available on google but no luck
0
Comment
Question by:GRChandrashekar
  • 3
  • 3
  • 2
8 Comments
 
LVL 26

Accepted Solution

by:
Shaun Kline earned 500 total points
ID: 39228842
What is your goal for filtering the datatable? Do you need to bind the result to control(s)? Do you need to find values in that same row?

The commented out line will return an array of datarows.
The second modifies the defaultview of the table, but not the table itself.

Try:
Dim dv as DataView = _title.DefaultView
dv.RowFilter = "<filter>"

Then use dv.
0
 

Author Comment

by:GRChandrashekar
ID: 39228861
Just need to filter the row which is having the pk value which am passing
0
 
LVL 70

Expert Comment

by:Éric Moreau
ID: 39228885
as started by shaun:

Dim dv as DataView = _title.DefaultView
dv.RowFilter =  "TitleID= '" + titleid.ToString() + "'"
0
Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

 

Author Comment

by:GRChandrashekar
ID: 39228886
Dim dv as DataView = _title.DefaultView
dv.RowFilter = "<filter>"

This filters the grid itself which has binding ! I just need to find row without affecting my databinding
0
 
LVL 70

Expert Comment

by:Éric Moreau
ID: 39228913
just bind your grid to the dataview instead of the datable!
0
 

Author Comment

by:GRChandrashekar
ID: 39228918
Didnt understand
0
 
LVL 26

Expert Comment

by:Shaun Kline
ID: 39228922
Going back to my original question, once you have the row with that PK, what are you going to do with it?

There are a number of ways to get that row in various object types. Understanding what you wish to do with the datarow will help us find an answer for you that works.
0
 
LVL 70

Expert Comment

by:Éric Moreau
ID: 39228925
your grid is currently bound to _title? make the dataview a member with a scope of the form and bind your grid to this new dataview variable
0

Featured Post

Best Practices: Disaster Recovery Testing

Besides backup, any IT division should have a disaster recovery plan. You will find a few tips below relating to the development of such a plan and to what issues one should pay special attention in the course of backup planning.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article explains how to create and use a custom WaterMark textbox class.  The custom WaterMark textbox class allows you to set the WaterMark Background Color and WaterMark text at design time.   IMAGE OF WATERMARKS STEPS Create VB …
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…

822 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question