C#中的DataGridView控件

时间:2016-12-11 20:12:23

标签: c# datagridview

enter image description here

大家好, 我正在尝试将我的数据库添加到" DatagridView,但是当我添加记录并单击删除并保存按钮时,它会抛出此错误" System.InvalidOperationException"并且记录未被删除。这有什么理由吗?我按照相应的步骤将数据库添加到表单中,但我一直收到此错误。

这是我与数据库的连接:

 <connectionStrings>
    <add name="Technician_Maintenace_Project_18_1.Properties.Settings.TechSupport_DataConnectionString"
        connectionString="Data Source=(LocalDB)\MSSQLLocalDB;AttachDbFilename=&quot;C:\Users\Momo Johnson\Desktop\TechSupport\TechSupport_Data.MDF&quot;;Integrated    Security=True;Connect Timeout=30"
        providerName="System.Data.SqlClient" />
</connectionStrings>

这是由visual studio生成的代码

namespace Technician_Maintenace_Project_18_1
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void techniciansBindingNavigatorSaveItem_Click(object sender, EventArgs e)
        {
            this.Validate();
            this.techniciansBindingSource.EndEdit();
            this.tableAdapterManager.UpdateAll(this.techSupport_DataDataSet);
        }

        private void Form1_Load(object sender, EventArgs e)
        {
            // TODO: This line of code loads data into the 'techSupport_DataDataSet.Technicians' table. You can move, or remove it, as needed.
            this.techniciansTableAdapter.Fill(this.techSupport_DataDataSet.Technicians);
        }
    }
}

FYI。数据库正在保存我添加的任何记录,但是当我按下删除键并保存时,它不会删除记录。

0 个答案:

没有答案