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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T18:27:35+00:00 2026-05-13T18:27:35+00:00

When I had a Typed DataTable with information retrieved from a SQL Server with

  • 0

When I had a Typed DataTable with information retrieved from a SQL Server with a table adapter, I’m able to insert temporary data into that DataTable which I just want to use on execution time, and I don’t want it to be inserted into the database.
First supose that for example I have a Database table like this:

CREATE TABLE MyData
(
    MyCol1 int,
    MyCol2 nchar(10)
)

So using SqlClient objects this is what I do.

MyTypedDataSet.MyTypedDataTable myDataTable = 
    new MyTypedDataSet.MyTypedDataTable();
myDataAdapter.Fill(myDataTable);
myDataTable.NewMyTypedRow(value1, value2);

I then could bind this to a control, e.g. a ComboBox

myComboBox.DataSource = myDataTable;
myComboBox.DisplayMember = "myCol2";
myComboBox.ValueMember = "myCol1";

How can I do the same with a LINQ to SQL Result such as:

var myQuery = from data in myContext.MyDatas
              select myCol1, myCol2;
myComboBox.DataSource = myQuery;

See, I want to add that extra row in myQuery, so that I can bind this data to my combo box, but I don’t want that extra row in my database.
I worked around it by calling the ToList() method, then I add the data I want, and then I bind this list to my ComboBox, like this:

var myList = myQuery.ToList();
myList.Insert(0, new MyData() { myCol1 = value1, myCol2 = value2 });
myComboBox.DataSource = myList;

… But how can I do this insert directly into myQuery? would it be a good practice? or my workaround would be the right thing to do?

PS: By the way, when I used to bind typed data tables to ComboBoxes I would use the schema generated names to asign values to DisplayMember and ValueMember like this:

myComboBox.DisplayMember = myDataTable.myCol1Column.ColumnName;
myComboBox.ValueMember = myDataTable.myCol2Column.ColumnName;

How can I extract this information from myQuery?

  • 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-13T18:27:35+00:00Added an answer on May 13, 2026 at 6:27 pm

    I think what you’re doing is fine.

    An alternative is instead of creating a list and inserting into it, you could create a new list containing one element and use the Concat method to concatenate the remaining elements. This can be a LINQ one-liner. But your way is probably more readable, so maybe just stick with that.

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

Sidebar

Ask A Question

Stats

  • Questions 302k
  • Answers 302k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer You can use an "OR" construct, to define possible forms… May 13, 2026 at 8:26 pm
  • Editorial Team
    Editorial Team added an answer The rule we follow with Seaside is not to mix… May 13, 2026 at 8:26 pm
  • Editorial Team
    Editorial Team added an answer You're not checking the result from port.Read(). It returns the… May 13, 2026 at 8:26 pm

Related Questions

I have a DataSet with a DataTable that correctly fills a single DataRow through
I have a variant on the by ref question. I know all about calling
This was a hard question for me to summarize so we may need to
One of my co-workers is building a C# windows app that needs to grab
I have a number of tables in my DB that hold references to an

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.