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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T13:03:21+00:00 2026-06-17T13:03:21+00:00

I need particular columns from datatable to bind it in DataGridView. I have following

  • 0

I need particular columns from datatable to bind it in DataGridView. I have following column.

Work1     Price     Area     que   Len     bre      size
A              12           x         1        1.2      1        1.2
A              12           y         2      2          2.2     4.4
A             12            z         3      11       1          11

Above is my data table and I need specifyed column i.e Area, Que, bre, size [Que * (bre * Len)]
To get this type of data I had used following Linq-to-DataTable query.

 var data = dt.AsEnumerable().Select
                (r => new
                {
                    Area = r.Field<string>("Area"),
                    Que = r.Field<int>("Quantity"),
                    Breath = r.Field<decimal>("Breath"),
                    Length = r.Field<decimal>("Length"),
                    totLen = r.Field<int>("Quantity") * (r.Field<decimal>("Breath") * r.Field<decimal>("Length"))
                }).ToList();

But its not working, It gives no value, I don’t know why??
Can any one tell me how can I do this?
And if there is any other alternate option is available than I love to see that…

  • 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-17T13:03:23+00:00Added an answer on June 17, 2026 at 1:03 pm

    It gives error “Specified cast is not valid.”

    So you’re getting an InvalidCastException in the Field extension method.

    You have to check which column’s type does not match to the one you’ve specified, for example:

    totLen = r.Field<int>("Quantity") * r.Field<decimal>("Breath") * r.Field<decimal>("Length")
    

    Above will fail if any of the three columns has a different type than the one you’ve provided. Maybe Breath is not a decimal but a double.

    Edit your question and provide the types in database and we could help to identify the correct types.

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

Sidebar

Related Questions

I need to place default text to all rows for particular column in jquery
I have some particular need to clone an element (image) and be draggable inside
I need my client to bind to a particular port and then connect to
I have a CGridView with columns from a table product => {'product_id','category_id',...} I have
I have two columns as company and product. I use the following query to
I have 15 tables with different column counts in mysql. Column count ranges from
I need to be able to determine from the DataTable returned by DbConnection.GetSchema() whether
I have three columns in my sql table, FirstName, MiddleName,LastName. When retrieving, I need
I have a situation where I need to get a series of objects from
I need to design a crystal report with 3 columns. Column 1 is a

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.