Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6769791
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T15:14:07+00:00 2026-05-26T15:14:07+00:00

Sorry about the confusing subject line :) I want to make a SQLlike query

  • 0

Sorry about the confusing subject line 🙂

I want to make a SQLlike query with my DataTable:s: I want to do something like this

// Is named "BadValues" Rows contain: id1, id2
DataTable tableReadFromFile = readFromFile();
// Is named "AllValues" Rows contain id1, id2
DataTable tableReadFromSql = readFromSql

DataTable resultTable = 
    tableReadFromFile.select("where AllValues.id1 not in (select id1 from BadValues) and AllValues.id2 not in (select id2 from BadValues)");

So if my “BadValues” table would look like this:

id1 id2
0    1
10   11
20   21

and my “AllValues” table would look like this:

id1 id2
0   1
0   2
1   1
10  11
10  12
12  11
20  21
20  22
22  21

I would like the resultTable to look like this:

id1 id2
0   2
1   1
10  12
12  11
20  22
22  21

In other words: if the pair id1,id2 exists in the table “BadValues” and in “AllValues” I want to remove them so that they don’t exist in the result table.

This would have been rather simple to do in SQL if the table “BadValues” would exist in the SQL database, but since it is loaded from file that is not possible.

As it is now, I loop through all rows in the “BadValues” and construct individual SQL queries with the id1 and id2 values set. Since I have quite a lot of data, that is very time consuming.

Any tip is appreciated!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T15:14:07+00:00Added an answer on May 26, 2026 at 3:14 pm

    Using Linq to dataset:

    var badValues = new HashSet<Tuple<int, int>>(
                      tableReadFromFile.AsEnumerable().
                                        Select(row => 
                                          new Tuple<int, int>(row.Field<int>("id1"), row.Field<int>("id2"))));
    
    var result = tableReadFromSql.AsEnumerable().
                                        Where(row => !(badValues.Contains(
                                        new Tuple<int, int>(row.Field<int>("id1"), row.Field<int>("id2")))));
    

    The first statement basically creates a hashset of the tuples which represent the bad values.

    The second searches in the second table the rows which ids are not in the hashset.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Sorry about the confusing title. I recently started doing this in my project, and
sorry about input mistakes, english its not my mother lang. I have this code
Sorry if this is wrong or confusing I am very new to using classes
Sorry for the confusing title of the question. I am uncertain about how should
Sorry about the confusing title, I had a hard time describing the problem. I
Sorry about the confusing title. Are there any web IDEs available that can be
[Please vote to close this - see my last comment.] Hi, Something like this:
me again. Sorry about this. Following on from my previous question (I think I
Sorry about that confusing title :) I have a resource, ComatosePage (used in the
Well, sorry about the confusing title but I'm having a slightly annoying problem with

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.