0

I am having trouble binding some data from my MySQL database to a DataGridView in C# Windows Forms.

I have 2 tables, referenced by a foreign key in one table, and I want to do a JOIN between the 2 tables and bind that to my DataGridView. I have tried adding a new datasource from a DataSet, but that only allows to add 1 table in the datagridview (as far as I can tell).

Next I wanted to create a Entity Framework model and bind that to the DataGridView. I have created a new model named Model1, but the model is not accessible anywhere in my code. Is there something wrong with my logic?

I have also tried (after creating the model) to create a DataSource from an object (trying to select the model as the object, but it wasn't visible in the wizard).

Or is there another way to bind a simple LEFT JOIN into a DataGridView?

Eduard Luca
  • 6,514
  • 16
  • 85
  • 137
  • I explain the best way I found to do it in my question http://stackoverflow.com/questions/21117217/best-aproach-to-bind-a-datagridview-to-database-entity-ies – Alejandro del Río Jan 21 '14 at 18:44

2 Answers2

1

Model1 is name of your EF Model not your context class,So in generated code by EF(Model1.Designer.cs), you must find a class that inherit from ObjectContext such as :

public partial class Entities : ObjectContext

and then:

new Entities().Table1....
Reza ArabQaeni
  • 4,848
  • 27
  • 46
1

One way you can do that by applying LINQ. Its same as EF but gives you more levity in between. Hope this helps!

You can write lamba expressions which perform Left Outer Join to your tables.

RG-3
  • 6,088
  • 19
  • 69
  • 125