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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T02:24:01+00:00 2026-06-01T02:24:01+00:00

I am learning ADO.NET entity framework. This is my first example. The datagrid seems

  • 0

I am learning ADO.NET entity framework. This is my first example. The datagrid seems to take the length of customers and not the actual column that I want to display. The following is the code.

public partial class NewCustomerForm : Form
{
    AFApp_H1Entities entities = new AFApp_H1Entities();
    public NewCustomerForm()
    {
        InitializeComponent();
    }

    private void NewCustomerForm_Load(object sender, EventArgs e)
    {
        var query = from c in entities.Customers
                        where c.ZIP == "77080"
                        select c.CustomerName;

        this.Controls.Add(dataGridView1);
        dataGridView1.DataSource = query;
    }
}

I was assuming I ll get some data which I am getting when running the same query in console application but in the grid its giving me the length of the names of customers. ?

  • 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-01T02:24:02+00:00Added an answer on June 1, 2026 at 2:24 am

    This code will give you an entry for every row returned by your query which is query.length() if you require something different you need to filter your results given this code.

    edit

    OK so this was bothering me so I wrote a small test case, I am guessing you are trying to use the entity framework (if not please post back), you do say ADO but your variable naming does indicate this may not be just plain old ADO.

    So Here is my database table create script.

    USE [Customers]
    GO
    
    /****** Object:  Table [dbo].[Customer]    Script Date: 04/02/2012 11:16:02 ******/
    SET ANSI_NULLS ON
    GO
    
    SET QUOTED_IDENTIFIER ON
    GO
    
    CREATE TABLE [dbo].[Customer](
        [id] [int] IDENTITY(1,1) NOT NULL,
        [Name] [nvarchar](50) NOT NULL,
        [Zip] [nvarchar](50) NOT NULL,
     CONSTRAINT [PK_Customer] PRIMARY KEY CLUSTERED 
    (
        [id] ASC
    )WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS  = ON, ALLOW_PAGE_LOCKS  = ON) ON [PRIMARY]
    ) ON [PRIMARY]
    
    GO
    

    Now in my appication is have this

    public partial class Form1 : Form
    {
        private readonly CustomersEntities _entities =
            new CustomersEntities(ConfigurationManager.ConnectionStrings["CustomersEntities"].ConnectionString);
    
        public Form1()
        {
            InitializeComponent();
        }
    
        private void Form1_Load(object sender, EventArgs e)
        {
            var query =
                _entities.Customers.Where(c => c.Zip == "12345").Select(
                    c => new CustomerDataBinding {Name = c.Name, Zip = c.Zip});
    
            Controls.Add(dataGridView1);
            dataGridView1.DataSource = query;
        }
    }
    
    public class CustomerDataBinding
    {
        public string Zip { get; set; }
        public string Name { get; set; }
    }
    

    I have three records in that database two with the same ZIP (it doesn’t matter its not a real zip format) and one without (insert your own data with sql).

    If i run this code I get two customers returned into the grid and not the three as is expected.

    Just a note, this is not exactly the best way to acheive this but works for a basic example.

    The app by the way looks this on run

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

Sidebar

Related Questions

I just recently started learning and using the ADO.NET Entity Framework and ran into
I am just starting out with ADO.net Entity Framework I have mapped two tables
I just starting learning, testing ADO.net Entity Data Models with MySql - everything is
OK, so I am learning the Entity Framework and LINQ to connect to a
I'm learning some ADO.NET. I noticed quite a few Database functionality can also be
I am learning ADO.NET But it very hard for me... I dont understand why
I'm learning SSIS and this seems like an easy task but I'm stuck. I
Learning WPF nowadays. Found something new today with .Net dependency properties. What they bring
Im learning lisp and im pretty new at this so i was wondering... if
Learning Ruby. Needed to create a hash of arrays. This works... but I don't

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.