日期:2014-05-18  浏览次数:20969 次

新人自学C Sharp 碰到问题要问
Hi ALL,


有以下代码出错了,同样的代码在另一表格中可就可执行,不明白问下各位。
C# code
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace HY_New
{
    public partial class frmProCla : Form
    {
        public frmProCla()
        {
            InitializeComponent();
        }
        private void ChangeEnableState() 
        {
            proClassTableBindingNavigator.Enabled = !proClassTableBindingNavigator.Enabled;
            
            gbEdit.Enabled = !gbEdit.Enabled;
           
            foreach (ToolStripButton b in tsControl.Items)
            {
                b.Enabled = !b.Enabled;
            }

        }

        private void frmProCla_Load(object sender, EventArgs e)
        {
            // TODO: 这行代码将数据加载到表“_DsHY_new.Department”中。您可以根据需要移动或删除它。
            this.departmentTableAdapter.Fill(this._DsHY_new.Department);
            // TODO: 这行代码将数据加载到表“_DsHY_new.ProClassTable”中。您可以根据需要移动或删除它。
            this.proClassTableTableAdapter.Fill(this._DsHY_new.ProClassTable);
        }

       private void tsbInsert_Click(object sender, EventArgs e)
        {
            ChangeEnableState();
            proClassTableBindingSource.AddNew();
            proClassNameTextBox.Focus();
        }

        private void tsbEdit_Click(object sender, EventArgs e)
        {
            ChangeEnableState();
            proClassNameTextBox.Focus();

        }

        private void tsbDelete_Click(object sender, EventArgs e)
        {
            if (proClassTableBindingSource.Current != null)
            {
                if (MessageBox.Show("确实要删除吗?", "确认", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
                {
                    proClassTableBindingSource.RemoveCurrent();
                    [color=#0000FF]this.tableAdapterManager.UpdateAll(this._DsHY_new);[/color]
                    //此处出错
                }
            }
        }

        private void tsbSave_Click(object sender, EventArgs e)
        {
            ChangeEnableState();
            this.Validate();
            this.proClassTableBindingSource.EndEdit();
            this.tableAdapterManager.UpdateAll(this._DsHY_new);
            //此处在新增时保存通过,在修改时保存出错。

        }

        private void tsbCancel_Click(object sender, EventArgs e)
        {
            ChangeEnableState();
            this.proClassTableBindingSource.CancelEdit();

        }
    }
}




------解决方案--------------------
你所谓的不行,怎么不行,报什么错