数据适配器无法更新 .NET 中添加/更新/删除的记录

发布于 2024-08-20 19:05:48 字数 938 浏览 2 评论 0原文

步骤,

  1. 具有单一表单的 Crate 窗口应用程序
  2. 从数据添加新数据源 -> 添加新数据源
  3. 转到数据 -> 显示数据源
  4. 将任何表拖放到表单中。此步骤将添加两个控件。一个。 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,

  1. Crate window application with single form
  2. add new datasource from Data->Add new Data source
  3. Goto Data->Show Data Source
  4. 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

八巷 2024-08-27 19:05:48

嘿,你还没有得到答案吗?

您需要向 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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文