【发布时间】:2016-08-31 16:41:37
【问题描述】:
我的程序允许用户编辑数据库中的数据。这是通过在一个表单上向用户显示“产品”,然后要求他们在另一个表单上插入正确数量的库存来实现的。
我正在尝试使带有“产品”的第一个表单被刷新,以显示第二个表单的修改后的数字,或者关闭第二个表单,或者通过单击第二个表单的按钮。
不幸的是,我不知道如何做到这一点。
我知道不是:
frm1 f1 = new frm1(this);
f1.Show();
修改表格代码:
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;
using System.Data.OleDb;
namespace InventoryManager
{
public partial class frmAdjustment : Form
{
frmAmendStock _main;
public string enteredSKU { get; set; }
public frmAdjustment(frmAmendStock main)
{
InitializeComponent();
_main = main;
}
private void frmAdjustment_Load(object sender, EventArgs e)
{
this.AcceptButton = btnSubmit;
}
private void btnCancel_Click(object sender, EventArgs e)
{
this.Close();
}
private void btnSubmit_Click(object sender, EventArgs e)
{
using (OleDbConnection connect = new OleDbConnection())
{
connect.ConnectionString = @"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=D:\Other\Documents\University Work\USB\Individual Project\Artefact\InventoryManager\InventoryManager\stock.mdb";
connect.Open();
OleDbCommand cmd = new OleDbCommand("UPDATE items SET Stock = @stock, Stock_Counted = @counted WHERE SKU LIKE '" +enteredSKU+"'", connect);
string units = txtAmount.Text;
if (connect.State == ConnectionState.Open)
{
if (string.IsNullOrEmpty(units))
{
MessageBox.Show("Please enter the correct amount of units.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Warning);
}
else
{
cmd.Parameters.Add("@stock", OleDbType.Integer, 5).Value = txtAmount.Text;
cmd.Parameters.Add("@counted", OleDbType.Integer, 5).Value = txtAmount.Text;
try
{
cmd.ExecuteNonQuery();
MessageBox.Show("Stock Adjusted", "Saved", MessageBoxButtons.OK, MessageBoxIcon.Information);
txtAmount.Clear();
connect.Close();
this.Close();
}
catch (Exception expe)
{
MessageBox.Show(expe.ToString());
connect.Close();
}
}
}
else
{
MessageBox.Show("Connection Failed");
}
}
}
}
}
【问题讨论】:
标签: c# winforms button refresh