I just started teaching myself Linq to SQL today. I hardly know anything about linq. That being said, I have a query that i want to return a Name from my database. It is a varchar in the DB
var query = from a in FRESH.Customers
select a.CUSTOMER_NAME;
dataGridView1.DataSource = query;
This results in a gridview with a column named “Length” and displays the length of every name. If I change the query to select a everything displays fine. What am I doing wrong here?
The
DataGridViewwill by default show all of the properties of the type in the list as columns. Since your query is returning a collection ofstrings and the only1 “property” of astringisLengthit shows that as a column.Try changing to
1Technically the indexer
Charsis a “property” but theDataGridViewmust be clever enough not to use an indexer as a column.