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

  • Home
  • SEARCH
  • 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 8862341
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T15:42:20+00:00 2026-06-14T15:42:20+00:00

With c# and LinqToSql I query a database Table and return a single unique

  • 0

With c# and LinqToSql I query a database Table and return a single unique record.

QUESTION:
How do I place the results of my query into a Dictionary with:
the Column Names of the database Table as the Dictionary Keys and
the Column Values of the database Table as the Dictionary Values.

Note: I will not always know the name or number of the Table’s Column Names

Dictionary<string, string> QueryResult = new Dictionary<string, string>

var UniqueRecord = (from tbl DataContext.Table
                                 where tbl.ColumnName1.Equals(Parameter1) 
                                 && tbl.ColumnName2.Equals(Parameter2)
                                 select tbl);

//How do I add var UniqueRecord to the Dictionary

==================================================================================

I eventually used this

==================================================================================

var UniqueRecord = (from tbl DataContext.Table
                                 where tbl.ColumnName1.Equals(Parameter1) 
                                 && tbl.ColumnName2.Equals(Parameter2)
                                 select tbl);


 foreach(var item in OnlineBezeichnungRekord)
 {
   var properties = item.GetType()
                        .GetProperties()
                        .ToDictionary(p => p.Name, p => p.GetValue(item, null).ToString());

   Dictionary<string,string> DictionaryValues = properties;

  }
  • 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-06-14T15:42:21+00:00Added an answer on June 14, 2026 at 3:42 pm

    Considering how simple it is to convert a DataRow into a Dictionary manually, I would not go with Enumerable.ToDictionary in your case, and just do loops:

    Private Function GetDictionaryFromDataRow(dr As DataRow) As Dictionary(Of String, Object)
      Dim dict As New Dictionary(Of String, Object)
      For Each col As DataColumn In dr.Table.Columns
        dict.Add(col.ColumnName, dr.Item(col))
      Next
      Return dict
    End Function
    

    Then just make sure your query returns a DataRow, so use UniqueRecord(0).

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

Sidebar

Related Questions

Ok, I have a LinqToXml query that returns a single record (correct terminology?), however,
I'm using LinqToSql to query a small, simple SQL Server CE database. I've noticed
Can any body help me to convert the following SQL query in LinqToSql syntax.
LINQToSQL doesn't like my sproc. It says that the sproc has return type none,
I am new to linqtosql. I have a database schema where, An employee can
I'm using LINQtoSQL and I want to return a list of matching records for
I am using LinqToSQL to process data from SQL Server to dump it into
I am trying to dynamically generate linqtosql query using LinqKit . I would like
I have a query in linqtosql that returns a LabelNumber: var q = from
I have a field in my database table that use to store an enumeration

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.