[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

SEARCHING DATATABLE

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

Featured Post

Important Lessons on Recovering from Petya

In their most recent webinar, Skyport Systems explores ways to isolate and protect critical databases to keep the core of your company safe from harm.

Question has a verified solution.

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

This article describes relatively difficult and non-obvious issues that are likely to arise when creating COM class in Visual Studio and deploying it by professional MSI-authoring tools. It is assumed that the reader is already familiar with the cla…
For those of you who don't follow the news, or just happen to live under rocks, Microsoft Research released a beta SDK (http://www.microsoft.com/en-us/download/details.aspx?id=27876) for the Xbox 360 Kinect. If you don't know what a Kinect is (http:…
Video by: ITPro.TV
In this episode Don builds upon the troubleshooting techniques by demonstrating how to properly monitor a vSphere deployment to detect problems before they occur. He begins the show using tools found within the vSphere suite as ends the show demonst…
Have you created a query with information for a calendar? ... and then, abra-cadabra, the calendar is done?! I am going to show you how to make that happen. Visualize your data!  ... really see it To use the code to create a calendar from a q…

656 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