访问数据库更新

Access Database Update

我有一个 datagridview 在按下按钮时不会更新。

显示access数据库table内容。

按钮代码:

private void updatebutton_Click(object sender, EventArgs e)
    {
        DialogResult dr = MessageBox.Show("Are you sure you want to update the stock level?", "Message", MessageBoxButtons.YesNoCancel, MessageBoxIcon.Information);
        if (dr == DialogResult.Yes)
        {
            this.hPTableAdapter.Update(inkDataSet.HP);
            inkGridView.Refresh();
            MessageBox.Show("Record Updated");
        }
    }

hPTableAdapter 中用于更新的字符串:

UPDATE HP
SET Black = ?, Cyan = ?, Magenta = ?, Yellow = ?

未显示任何错误,在 Visual Studio 2015 年关闭应用程序并重新运行之前似乎一直有效。

完整代码:

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace Ink
{
    public partial class inkForm : Form
    {

        public inkForm()
        {
            InitializeComponent();
        }

        private void searchbutton_Click(object sender, EventArgs e)
        {
            int itemrow = -1;
            String searchValue = searchtextBox.Text.ToUpper();

            if (searchValue != null && searchValue != "")
            {
                foreach (DataGridViewRow row in inkGridView.Rows)
                {
                    if (row.Cells[1].Value.ToString().Equals(searchValue))
                    {
                        itemrow = row.Index;
                        break;
                    }
                    else if (row.Cells[0].Value.ToString().Contains(searchValue) && itemrow == -1)
                    {
                        itemrow = row.Index;
                    }
                }
                if (itemrow == -1)
                {
                    searchtextBox.BackColor = Color.Red;
                }
                else
                {
                    searchtextBox.BackColor = Color.White;
                    inkGridView.Rows[itemrow].Selected = true;
                    inkGridView.FirstDisplayedScrollingRowIndex = itemrow;
                }
            }
        }

        private void inkForm_Load(object sender, EventArgs e)
        {
            this.hPTableAdapter.Fill(this.inkDataSet.HP);

        }

        private void updatebutton_Click(object sender, EventArgs e)
        {
            DialogResult dr = MessageBox.Show("Are you sure you want to update the stock level?", "Message", MessageBoxButtons.YesNoCancel, MessageBoxIcon.Information);
            if (dr == DialogResult.Yes)
            {
                this.hPTableAdapter.Update(inkDataSet.HP);
                inkGridView.Refresh();
                MessageBox.Show("Record Updated");
            }
        }

        private void inkGridView_CellContentClick(object sender, DataGridViewCellEventArgs e)
        {

        }
    }
}

连接字符串中需要完整的数据库路径。