Check if item is contained in column of a datatable in 2005

Posted on 2007-08-02
Last Modified: 2013-11-26

I have the following code:-

        SQL = "Select * from Locations"
        Dim da As New SqlClient.SqlDataAdapter(SQL, oConn)
        da.Fill(ds, "Locations") ' populate data set "da" with the data returned from sql command "ds" and set dataset name to "Rigs"
        DataGridView1.DataSource = ds.Tables("Locations")

Basically it returns 3 columns - locationID, Stock_Location and Location_Description and places the retrieved data into a datatable. I am trying to find out how I can check if the string in textbox1.text is already in the column Stock_Location please in the datatable

Many thanks
Question by:ljhodgett
    1 Comment
    LVL 53

    Accepted Solution

    I see 2 possibilities:

    1. Perform it with a sql-statement: SQL = "Select * from Locations where Stock_Location '" & Textbox1.Text & "'"
    2. Filter your dataset
    ds.Tables("Locations").DefaultView.RowFilter = "Stock_Location =''" & Textbox1.Text & "'"
    if ds.Tables("Locations").DefaultView.Count > 0 then
      --> record found

    Featured Post

    How your wiki can always stay up-to-date

    Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
    - Increase transparency
    - Onboard new hires faster
    - Access from mobile/offline

    Join & Write a Comment

    This document covers how to connect to SQL Server and browse its contents.  It is meant for those new to Visual Studio and/or working with Microsoft SQL Server.  It is not a guide to building SQL Server database connections in your code.  This is mo…
    More often than not, we developers are confronted with a need: a need to make some kind of magic happen via code. Whether it is for a client, for the boss, or for our own personal projects, the need must be satisfied. Most of the time, the Framework…
    Migrating to Microsoft Office 365 is becoming increasingly popular for organizations both large and small. If you have made the leap to Microsoft’s cloud platform, you know that you will need to create a corporate email signature for your Office 365…
    Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…

    746 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

    15 Experts available now in Live!

    Get 1:1 Help Now