数据适配器无法更新 .NET 中添加/更新/删除的记录
步骤,
- 具有单一表单的 Crate 窗口应用程序
- 从数据添加新数据源 -> 添加新数据源
- 转到数据 -> 显示数据源
- 将任何表拖放到表单中。此步骤将添加两个控件。一个。 DataGridView B.绑定导航器
按F5运行。
我可以查看所有记录,但无法添加/更新/删除。
下面是VS生成的表单的代码。
namespace TestingGrid
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void testBindingNavigatorSaveItem_Click( object sender, EventArgs e )
{
this.Validate();
this.testBindingSource.EndEdit();
this.testTableAdapter.Update( this.testDataSet.Test );
}
private void Form1_Load( object sender, EventArgs e )
{
// TODO: This line of code loads data into the 'testDataSet.Test' table. You can move, or remove it, as needed.
this.testTableAdapter.Fill( this.testDataSet.Test );
}
}
}
Steps,
- Crate window application with single form
- add new datasource from Data->Add new Data source
- Goto Data->Show Data Source
- Drop any table to form. This step will add tow controls. a. DataGridView b. Binding Navigator
press F5 to run.
I am able to view all the records but not able to do add/update/delete.
Below is the code of the form that is generated by VS.
namespace TestingGrid
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void testBindingNavigatorSaveItem_Click( object sender, EventArgs e )
{
this.Validate();
this.testBindingSource.EndEdit();
this.testTableAdapter.Update( this.testDataSet.Test );
}
private void Form1_Load( object sender, EventArgs e )
{
// TODO: This line of code loads data into the 'testDataSet.Test' table. You can move, or remove it, as needed.
this.testTableAdapter.Fill( this.testDataSet.Test );
}
}
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
嘿,你还没有得到答案吗?
您需要向 sql 表添加主键。
如果没有主键,数据适配器将无法删除或编辑任何记录。
我只是使用了一个自动递增的 Id 整数;所以我不需要在我的数据网格视图中显示 id。
Hey did you not get a answer yet?
You need to add a primary key to your sql table.
without the primary key the data adapter will not be able to delete or edit any records.
i just used a Id integer that auto increments; so i do not need to show the id in my datagrid view.