?
Solved

SEARCHING DATATABLE

Posted on 2011-09-17
5
Medium Priority
?
292 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
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 2000 total points
ID: 36554098
No it'll be like
      dim idx as string
      idx = "P114"
      dt.DefaultView.RowFilter = "id='" & idx & "'"
0

Featured Post

Free Backup Tool for VMware and Hyper-V

Restore full virtual machine or individual guest files from 19 common file systems directly from the backup file. Schedule VM backups with PowerShell scripts. Set desired time, lean back and let the script to notify you via email upon completion.  

Question has a verified solution.

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

Creating an analog clock UserControl seems fairly straight forward.  It is, after all, essentially just a circle with several lines in it!  Two common approaches for rendering an analog clock typically involve either manually calculating points with…
In real business world data are crucial and sometimes data are shared among different information systems. Hence, an agreeable file transfer protocol need to be established.
Integration Management Part 2
With just a little bit of  SQL and VBA, many doors open to cool things like synchronize a list box to display data relevant to other information on a form.  If you have never written code or looked at an SQL statement before, no problem! ...  give i…
Suggested Courses

840 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