sol*_*jic 12 c# entity-framework datasource datagridview winforms
我尝试通过DataGridView Designer设置DataSource但它没有在那里列出,然后我通过生成DataSet的向导生成了新的数据源.
但是现在我的项目+ DataSet中有Entity Framework我怎么才能使用Entity Framework ...我很困惑请帮助
artiklBindingSource
是自动生成我只想使用EF作为数据源现在我被困在不需要的DataSet和一堆乱七八糟的东西.
Rez*_*aei 17
要添加具有使用数据源您DataGridView
在DataGridView的任务面板中,打开选择数据源:组合框,然后:
这是代码示例:
using System;
using System.Windows.Forms;
using System.Data.Entity;
namespace WindowsFormsApplication
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
SampleDBEntities db;
private void Form1_Load(object sender, EventArgs e)
{
db = new SampleDBEntities();
db.Products.Load();
this.productBindingSource.DataSource = db.Products.Local.ToBindingList();
}
private void SaveButton_Click(object sender, EventArgs e)
{
db.SaveChanges();
}
private void Form1_FormClosed(object sender, FormClosedEventArgs e)
{
db.Dispose();
}
}
}
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
14874 次 |
最近记录: |