Solved

SEARCHING DATATABLE

Posted on 2011-09-17
5
288 Views
Last Modified: 2012-05-12
Hi Experts
The following code
   DA.Fill(DS, "Codes")
        dt = DS.Tables("codes")
       grid2.DataSource = dt
shows:-
             id                     desc                      qty
          P113                   PADS                       2
          P114                   PADS                       5
          P115                   PADS                       6
I would like to only show middle line in grid3
and like to store id (P114) to veriable idx
                           qty(5)     to              qtyx

Thanks
0
Comment
Question by:b001
[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
5 Comments
 
LVL 38

Expert Comment

by:Tom Beck
ID: 36554005
Dim dt2 As New Data.DataTable
Dim idx As String = String.Empty
Dim qtyx As String = String.Empty
Dim dr As Data.DataRow
Dim dr2 As Data.DataRow
For Each dr In dt.Rows
     If String.Compare(dr.Item(0), "P114", true) = 0 Then
          idx = dr.Item(0)
          qtyx = dr.Item(2)
          dr2 = dt2.NewRow()
          dr2.Item(0) = dr.Item(0)
          dr2.Item(1) = dr.Item(1)
          dr2.Item(2) = dr.Item(2)
          dt2.Rows.Add(dr2)
     End If
Next
grid3.DataSource = dt2
0
 
LVL 4

Expert Comment

by:guramrit
ID: 36554017
Use RowFilter to filter rows in gridView
   DA.Fill(DS, "Codes")
        dt = DS.Tables("codes")
      dt.DefaultView.RowFilter = "id='P114'"
       grid2.DataSource = dt
 
now grid will show:-
             id                     desc                      qty
         P114                   PADS                       5
 
you can also retreive values of id and qty as follows:
       Dim idx as string
       Dim qtyx as integer
       idx = dt.DefaultView(0)(0)
       qtyx = dt.DefaultView(0)(1)

because dt.DefaultView contains only one row, the filtered row. That's why I wrote dt.DefaultView(0).
0
 
LVL 14

Expert Comment

by:binaryevo
ID: 36554019
0
 

Author Comment

by:b001
ID: 36554070
HI guramrit:
Thanks it works ok
 
      dt.DefaultView.RowFilter = "id='P114'"

What about if P114 is stored to veriable IDX
would the code chage to

      dt.DefaultView.RowFilter = "id='IDX'"

or something different

Thanks
0
 
LVL 4

Accepted Solution

by:
guramrit earned 500 total points
ID: 36554098
No it'll be like
      dim idx as string
      idx = "P114"
      dt.DefaultView.RowFilter = "id='" & idx & "'"
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
This video shows how to use Hyena, from SystemTools Software, to update 100 user accounts from an external text file. View in 1080p for best video quality.

737 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