访问数据库更新

时间:2015-04-21 14:36:12

标签: c# ms-access-2010

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

显示访问数据库表内容。

按钮代码:

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)
        {

        }
    }
}

1 个答案:

答案 0 :(得分:0)

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