Solved

Filter Datatable

Posted on 2013-06-07
8
294 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Revamp Your Training Process

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action.

 

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

Online Training Solution

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.

Question has a verified solution.

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

Since .Net 2.0, Visual Basic has made it easy to create a splash screen and set it via the "Splash Screen" drop down in the Project Properties.  A splash screen set in this manner is automatically created, displayed and closed by the framework itsel…
Microsoft Reports are based on a report definition, which is an XML file that describes data and layout for the report, with a different extension. You can create a client-side report definition language (*.rdlc) file with Visual Studio, and build g…
Monitoring a network: why having a policy is the best policy? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the enormous benefits of having a policy-based approach when monitoring medium and large networks. Software utilized in this v…
If you’ve ever visited a web page and noticed a cool font that you really liked the look of, but couldn’t figure out which font it was so that you could use it for your own work, then this video is for you! In this Micro Tutorial, you'll learn yo…

726 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