Solved

Reading from one column in a Dataset

Posted on 2006-06-30
2
194 Views
Last Modified: 2010-04-23
Hi all,

I have a Dataset in my app populated with 10 columns of data. I also have a ComboBox that contains all the names of the columns. What I am trying to achieve is, when a user selects a column name from the ComboBox my app should look at the data in my Dataset from the selected column only and try to find a predefined value. If not found then it should pop up a message box. If all data in the column does match the predefined value then a different message box pops up.

Can someone give me a code example of how to do this as I am having a bit of trouble trying to figure it out.

Many Thanks.
0
Comment
Question by:kiranboi
2 Comments
 
LVL 17

Accepted Solution

by:
ZeonFlash earned 500 total points
ID: 17018259
From your description, this is what I came up with:

    Dim objPredefinedValue As Object = "Predefined Value"

    Private Sub ComboBox1_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ComboBox1.SelectedIndexChanged
        Dim intMatchesFound As Integer = 0

        For Each row As DataRow In dsDataset.Tables(0).Rows
            If row.Item(ComboBox1.SelectedValue) = objPredefinedValue Then intMatchesFound += 1
        Next

        If intMatchesFound = 0 Then : MsgBox("No match found")
        ElseIf intMatchesFound = dsDataset.Tables(0).Rows.Count Then : MsgBox("All rows match")
        Else : MsgBox(intMatchesFound & " matches found")
        End If
0
 

Author Comment

by:kiranboi
ID: 17018339
Works great, thanks
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone 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

Article by: jpaulino
XML Literals are a great way to handle XML files and the community doesn’t use it as much as it should.  An XML Literal is like a String (http://msdn.microsoft.com/en-us/library/system.string.aspx) Literal, only instead of starting and ending with w…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
Microsoft Active Directory, the widely used IT infrastructure, is known for its high risk of credential theft. The best way to test your Active Directory’s vulnerabilities to pass-the-ticket, pass-the-hash, privilege escalation, and malware attacks …
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

856 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