我的程序允许用户编辑数据库中的数据。这通过向用户显示"产品"在一个表格上然后要求他们在另一个表格上插入正确数量的股票。
我正在努力使第一个形式与"产品"刷新以显示第二种形式的修正数字,或者关闭第二种形式,或者通过按钮点击第二种形式。
遗憾的是,我不知道该怎么做。
我知道它不是:
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");
}
}
}
}
}
答案 0 :(得分:0)
示例:`
if (f1.ShowDialog(this) == DialogResult.OK){
var stock = f1.Stock;
}
有道理吗?