在c#中编辑和保存来自Microsoft Access的结果

本文关键字:Microsoft Access 结果 保存 编辑 | 更新日期: 2023-09-27 18:14:42

我正在自己的POS系统上工作,我使用此代码尝试使应用程序编辑项目的"数量"。我所做的是我有一个搜索栏,我可以搜索条形码ID和数据将显示在文本框中。(例如:原始数量将显示在textBox1中。我会得到那个textBox。文本+"1"[我不打算在这里详细说明,但它可以工作,如果你确实需要代码],请注释)。现在我想链接和编辑数据到Access数据库,并从第二个文本框(具有原始文本框+1)插入结果错误如下:错误图片

代码如下:

       using System.Data.OleDb;
       using System.Drawing.Printing;
       using System.IO;
       using System.Drawing.Imaging;
       namespace TestBarcode
                {
                        public partial class POS : Form
                {
          private OleDbConnection connection = new OleDbConnection();

    public POS()
    {
        InitializeComponent();
            connection.ConnectionString=@"Provider=Microsoft.ACE.OLEDB.12.0;DataSource=C:'POS'Database'MainDatabase_POS.accdb;
        Persist Security Info=False;";
    }
        private void POS_Load(object sender, EventArgs e)
    {
          this.inventoryManagementTableAdapter.Fill(this.mainDatabase_POSDataSet.InventoryManagement);
        checkBox1.Show();
        checkBox2.Hide();
        try
        {
            connection.Open();
            OleDbCommand command = new OleDbCommand();
            command.Connection = connection;
            string query = "select * from InventoryManagement";
            command.CommandText = query;
            OleDbDataAdapter da = new OleDbDataAdapter(command);
            DataTable dt = new DataTable();
            da.Fill(dt);
            dataGridView1.DataSource = dt;
            connection.Close();
        }
        catch (Exception ex)
        {
            MessageBox.Show("Error" + ex);
        }
     }

  try
        {
            connection.Open();
            OleDbCommand command = new OleDbCommand();
            command.Connection = connection;
   //EditTextHere
           string query = "UPDATE InventoryManagement set Số_Lượng_Trong_Kho='" + textBox25.Text + "',Mã_Số_Vạch='" + textBox19.Text + "',Mã_thợ='" + textBox13.Text + "',Kiểu='" + textBox14.Text + "',Size_Giày='" + textBox15.Text + "',Màu='" + textBox16.Text + "',Giá='" + textBox17.Text + "'where ID=" + textBox24.Text + "";
command.CommandText = query;
            command.ExecuteNonQuery();
            MessageBox.Show(query);
            connection.Close();
        }
        catch (Exception ex)
        {
            MessageBox.Show("Error" + ex);
        }

PS:(1)忽略越南语文本,如果你喜欢,你可以用任何单词替换这些单词。

(2)对不起,我把文本框搞砸了,所以文本框的名字是随机的,很难理解。

有办法让这发生吗?如果有,请帮忙。谢谢。

在c#中编辑和保存来自Microsoft Access的结果

似乎您正在传递错误的数据类型的参数。请检查从文本框& &;传入的值的数据类型。数据库表的列。我相信会有一些比赛错过。