0

脚步,

  1. 具有单一表单的 Crate 窗口应用程序
  2. 从数据添加新数据源->添加新数据源
  3. 转到数据-> 显示数据源
  4. 删除任何表格以形成。此步骤将添加两个控件。一个。数据网格视图 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 );

        }
    }
}
4

1 回答 1

1

嘿,你还没得到答案吗?

您需要向您的 sql 表添加一个主键。如果没有主键,数据适配器将无法删除或编辑任何记录。

我只是使用了一个自动递增的 Id 整数;所以我不需要在我的数据网格视图中显示 id。

于 2010-11-29T12:40:28.083 回答