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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T12:18:14+00:00 2026-06-04T12:18:14+00:00

I’ve this linq query and don’t know why it is not working. itemDetails is

  • 0

I’ve this linq query and don’t know why it is not working. itemDetails is my Datatable.I am a beginner.

What I want is to get the itemID for an item whenever it is selected in the datagridview combobox field.

1) One problem is with the linq query I’ve written below.

    from r in itemDetails
    where r.ItemName = dataGridView1.Rows[e.RowIndex].Cells[0].Value.ToString()
    select r.ItemID;

It is giving the following error

Could not find an implementation of the query pattern for source type
‘System.Data.DataTable’. ‘Where’ not found.

2) The other problem is that how can I work on datagridview combobox selectedIndexchanged event

  • 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-04T12:18:17+00:00Added an answer on June 4, 2026 at 12:18 pm

    The problem you’re having is that a DataTable is not an IEnumerable class, meaning you will not be able to use Linq methods on it. That’s what the compiler’s complaining about; the Linq query you’ve written is compiled into a series of method calls, and the compiler expects to find a Where() method that it can call on a DataTable to perform the where clause’s filtering, and doesn’t find one.

    However, its Rows property is IEnumerable (but not generic, so you’ll need to use the OfType() method to create an IEnumerable of DataRows):

    from r in itemDetails.Rows.OfType<DataRow>()
    where r.ItemName == dataGridView1.Rows[e.RowIndex].Cells[0].Value.ToString()
    select r.ItemID;
    

    Now, on top of that, DataRow does not have properties ItemName and ItemID. You don’t get values from a DataRow that way. The compiler isn’t complaining about that in your code (yet) because it doesn’t even know what the type of r is, so it can’t determine whether objects of that type have those members. Once you specify that r is a DataRow, the compiler will pick up the additional errors.

    To fix that, you’ll need to use the indexer available on a DataRow. You can either refer to the columns by index (zero-based from left to right based on the select list of the query that hydrated the DataTable), or by column name (again based on the names of the columns or the aliases you give them in the select list):

    from r in itemDetails.Rows.OfType<DataRow>()
    where r["ItemName"].ToString() == dataGridView1.Rows[e.RowIndex].Cells[0].Value.ToString()
    select (int)r["ItemID"];
    

    The items produced by the indexer are of type Object; you will need to cast or convert them to the proper type (I’m assuming, for instance, that ItemName is a String and that ItemId is a 32-bit integer).

    As for your second question, DataGridViews don’t expose most of the events of their contained controls. Instead, those controls are hooked into, and cause the DGV to fire its own events which you can handle. Take a look at the CellValueChanged event and/or the CellDirtyStatusChanged event. The first one is raised when the user changes a cell’s value and then that cell loses focus. CellDirtyStatusChanged is raised as soon as the first change is made to the cell’s value, before a commit actually occurs.

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

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
Does anyone know how can I replace this 2 symbol below from the string
For some reason, after submitting a string like this Jack’s Spindle from a text
I want to count how many characters a certain string has in PHP, but
link Im having trouble converting the html entites into html characters, (&# 8217;) i
this is what i have right now Drawing an RSS feed into the php,
I have this code to decode numeric html entities to the UTF8 equivalent character.
I have a French site that I want to parse, but am running into
I want use html5's new tag to play a wav file (currently only supported

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.