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. ?
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.
Now in my appication is have this
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
on run