Solved

SEARCHING DATATABLE

Posted on 2011-09-17
5
284 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
Comment Utility
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
Comment Utility
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
Comment Utility
0
 

Author Comment

by:b001
Comment Utility
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
Comment Utility
No it'll be like
      dim idx as string
      idx = "P114"
      dt.DefaultView.RowFilter = "id='" & idx & "'"
0

Featured Post

What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

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:…
A long time ago (May 2011), I have written an article showing you how to create a DLL using Visual Studio 2005 to be hosted in SQL Server 2005. That was valid at that time and it is still valid if you are still using these versions. You can still re…
When you create an app prototype with Adobe XD, you can insert system screens -- sharing or Control Center, for example -- with just a few clicks. This video shows you how. You can take the full course on Experts Exchange at http://bit.ly/XDcourse.
You have products, that come in variants and want to set different prices for them? Watch this micro tutorial that describes how to configure prices for Magento super attributes. Assigning simple products to configurable: We assigned simple products…

772 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

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now