private void btnSave_Click(object sender, EventArgs e)
        {
            DialogResult result;
            result = MessageBox.Show("确定","操作提示",MessageBoxButtons.OKCancel,MessageBoxIcon.Question);
            if (result == DialogResult.OK)
            {
                this.productsTableAdapter.Update(this.superMarketDataSet);
            }
        }
新手。C#2005软件
很简单的一个练习的例子,按下按钮就应该保存。现在的现象是如果在下面新建一行能够保存。如果是在原数据修改后家就会在【this.productsTableAdapter.Update(this.superMarketDataSet);】这一行出现中断。书上写:因为程序自动生成DataSet和DataAdapter,所以不需要手动创建SqlCommandBuilder

解决方案 »

  1.   

    this.productsTableAdapter.Update(this.superMarketDataSet); 
    这句是什么意思看不懂,你到底要实现什么功能呀,是想吧dataGridView的内容保存到哪里呀?
      

  2.   

    书上的意思是sqlDataAdapter和dataset是拖动的控件过来,已经建立过数据连接,高级选项中选中要生产的几个命令,之后才能更新。可以到designer里看看有没有对应的command。
      

  3.   

    错误内容:当传递具有已修改行的 DataRow 集合时,更新要求有效的 UpdateCommand。
    design生成的代码如下。
            private System.Windows.Forms.DataGridView dataGridView1;
            private System.Windows.Forms.Button button1;
            private SuperMarketDataSet superMarketDataSet;
            private System.Windows.Forms.BindingSource productsBindingSource;
            private WindowsApplication1.SuperMarketDataSetTableAdapters.productsTableAdapter productsTableAdapter;
            private System.Windows.Forms.DataGridViewTextBoxColumn idDataGridViewTextBoxColumn;
            private System.Windows.Forms.DataGridViewTextBoxColumn productnameDataGridViewTextBoxColumn;
            private System.Windows.Forms.DataGridViewTextBoxColumn barcodeDataGridViewTextBoxColumn;
            private System.Windows.Forms.DataGridViewTextBoxColumn amountDataGridViewTextBoxColumn;
            private System.Windows.Forms.DataGridViewTextBoxColumn priceDataGridViewTextBoxColumn;
            private System.Windows.Forms.Button btnSave;