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 6805227
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T19:33:40+00:00 2026-05-26T19:33:40+00:00

I have a list of objects that I retrieved from a web service call

  • 0

I have a list of objects that I retrieved from a web service call and I need to match them up against some rows in one of my database tables. My object has a few properties:

Name - string
Type - string

Together Name and Type would bring back a unique item in my database:

SELECT * FROM dbo.MyTable WHERE SomeName = @Name AND SomeType = @Type

This works fine; however, I have a list of Name/Type pairs and need to match against rows in my database:

List<Tuple> values = [{ "Name1", "Type1" }, { "Name2", "Type2" }, { "Name3", "Type3" }]

How could i write a query in SQL that would return a list of items based on a list of tuples. The format above is not actually the format of my values, so don’t worry about writing some parsing logic to get the values.

  • 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-26T19:33:41+00:00Added an answer on May 26, 2026 at 7:33 pm

    You could use Table-Valued Parameters in SQL Server 2008 (ADO.NET).

    SQL

    CREATE TYPE [dbo].[MyTableType] AS TABLE
    (
        [SomeName] NVARCHAR(50),
        [SomeType] NVARCHAR(50)
    )
    
    CREATE TABLE [dbo].[MyTable]
    (
        [SomeName] NVARCHAR(50),
        [SomeType] NVARCHAR(50)
    )
    
    INSERT  [dbo].[MyTable]
    VALUES  ('Name1', 'Type1'),
            ('Name2', 'Type2'),
            ('Name3', 'Type3'),
            ('Name4', 'Type4')
    

    C#

    var values = new List<Tuple<string, string>> { Tuple.Create("Name1", "Type1"), Tuple.Create("Name2", "Type2"), Tuple.Create("Name3", "Type3") };
    
    var dataTable = new DataTable();
    dataTable.Columns.Add(new DataColumn("SomeName", typeof(string)));
    dataTable.Columns.Add(new DataColumn("SomeType", typeof(string)));
    
    values.ForEach(v => dataTable.Rows.Add(v.Item1, v.Item2));
    
    using (var connection = new SqlConnection(@"Data Source=.;Initial Catalog=Tom;Integrated Security=True"))
    {
        using (var command = new SqlCommand())
        {
            command.Connection = connection;
            command.CommandText =
                "SELECT * " +
                "FROM [dbo].[MyTable] mt " +
                "INNER JOIN @MyTableType mtt " +
                "   ON mt.[SomeName] = mtt.[SomeName] " +
                "   AND mt.[SomeType] = mtt.[SomeType]";
    
            SqlParameter parameter = command.Parameters.AddWithValue("@MyTableType", dataTable);
            parameter.SqlDbType = SqlDbType.Structured;
            parameter.TypeName = "[dbo].[MyTableType]";
    
            connection.Open();
            SqlDataReader reader = command.ExecuteReader();
    
            while (reader.Read())
            {
                Console.WriteLine("mt.[SomeName]: {0}, mt.[SomeType]: {1}, mtt.[SomeName]: {2}, mtt.[SomeType]: {3}", 
                    reader.GetString(0), reader.GetString(1), reader.GetString(2), reader.GetString(3));
            }
        }
    }
    
    Console.ReadKey();
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a list of pointers that reference time objects that need a turn
I have a list of IDs for objects that I need to grab, then
I have a list of objects, that are pre-sorted based on some complex criteria
I have an application which has to handle a list of objects (retrieved from
I have a webpage that uses JavaScript to retrieve JSON from a web service.
I have a large collection of custom objects that I have retrieved from a
I have a list of AutomationPattern objects retrieved from the AutomationElement.GetSupportedPatterns() method. And now
I have a list of objects that have two int properties. The list is
I have a List of objects that I would like to convert to a
I have a List of String objects that are pipe delimited. something like this:

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.