[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

How to Query a Table Created Within C#

Posted on 2011-10-26
4
Medium Priority
?
411 Views
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#?
0
Comment
Question by:thenthorn1010
  • 2
4 Comments
 
LVL 10

Accepted Solution

by:
himanshut earned 1000 total points
ID: 37035687
0
 
LVL 10

Assisted Solution

by:himanshut
himanshut earned 1000 total points
ID: 37035689
0
 
LVL 20

Assisted Solution

by:ddayx10
ddayx10 earned 500 total points
ID: 37035897
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.

EX.

        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";
        table.Rows.Add(r1);
        table.Rows.Add(r2);

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

Assisted Solution

by:Srinivasulu Muppala
Srinivasulu Muppala earned 500 total points
ID: 37037471
Just try this

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

you can bind the resultRows into grid or some other.
0

Featured Post

Restore individual SQL databases with ease

Veeam Explorer for Microsoft SQL Server delivers an easy-to-use, wizard-driven interface for restoring your databases from a backup. No expert SQL background required. Web interface provides a complete view of all available SQL databases to simplify the recovery of lost database

Question has a verified solution.

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

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…
The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project
this video summaries big data hadoop online training demo (http://onlineitguru.com/big-data-hadoop-online-training-placement.html) , and covers basics in big data hadoop .
Look below the covers at a subform control , and the form that is inside it. Explore properties and see how easy it is to aggregate, get statistics, and synchronize results for your data. A Microsoft Access subform is used to show relevant calcul…
Suggested Courses

872 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