How to Query a Table Created Within C#

Posted on 2011-10-26
Last Modified: 2013-12-16
I am reading in data from a flat file and populating the data from the flat file into a table in C#, and I was wondering how I would query the table to get all of the results that match certain criteria. For instance, let's say that you create a table called "table1" with columns called "color, size, quantity". How would I execute the query "Select * from table1 where color = 'blue'" within C#?
Question by:thenthorn1010
    LVL 10

    Accepted Solution

    LVL 10

    Assisted Solution

    LVL 20

    Assisted Solution

    I dont think you can do much with a straight WebControls.Table without a lot of effort, but you should be able to easily use whatever code you have with a System.Data.DataTable which is completely queryable.


            DataTable table = new DataTable("Table1");
            table.Columns.Add("Column1", typeof(Int32));
            table.Columns.Add("Column2", typeof(String));
            DataRow r1 = table.NewRow();
            r1[0] = 1;
            r1[1] = "Row1Column2Text";
            DataRow r2 = table.NewRow();
            r2[0] = 2;
            r2[1] = "Row2Column2Text";

            DataRow[] rows = table.Select("Column1 = 2");
    LVL 4

    Assisted Solution

    by:Srinivasulu Muppala
    Just try this

    DataRow[] resultRows = table1.Select("color = 'blue'");

    you can bind the resultRows into grid or some other.

    Featured Post

    Courses: Start Training Online With Pros, Today

    Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

    Join & Write a Comment

    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…
    It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
    It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.
    Sending a Secure fax is easy with eFax Corporate ( First, Just open a new email message.  In the To field, type your recipient's fax number You can even send a secure international fax — just include t…

    755 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

    21 Experts available now in Live!

    Get 1:1 Help Now