0
データベース内の値を更新できるように、あるウィンドウフォームのテキストボックスの値を使用しようとしていますが、エラーが発生していますAn object reference is required for the non static field, method or property 'InventoryManager.frmAdjustment.enteredSku.get'
別のウィンドウフォームのテキストボックスの値を使用する
何か提案がありがとうございます。
コード:
AmendStock
private void btnSubmit_Click(object sender, EventArgs e)
{
lblLastChecked.Text = "";
lblPrice.Text = "";
lblStock.Text = "";
lblStockCounted.Text = "";
string SKU = txtSKU.Text;
string Select = "SELECT * FROM items WHERE SKU LIKE '" + SKU + "'";
string cs = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=|DataDirectory|\\stock.mdb";
DataConnection = new OleDbConnection(cs);
OleDbDataAdapter ida = new OleDbDataAdapter(Select, DataConnection);
DataSet product = new DataSet();
ida.Fill(product);
if (string.IsNullOrEmpty(SKU))
{
MessageBox.Show("Please enter a SKU.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Warning);
}
else
{
foreach (DataRow dr in product.Tables[0].Rows)
{
lblLastChecked.Text += Convert.ToDateTime(product.Tables[0].Rows[0]["Last_Counted"]).ToString("dd/MM/yyyy");
lblPrice.Text += "£" + product.Tables[0].Rows[0]["Price"].ToString();
lblStock.Text += product.Tables[0].Rows[0]["Stock"].ToString() + " units";
lblStockCounted.Text += product.Tables[0].Rows[0]["Stock_Counted"].ToString() + " units";
byte[] bimg = (byte[])product.Tables[0].Rows[0]["Image"];
var ms = new System.IO.MemoryStream(OleImageUnwrap.GetImageBytesFromOLEField(bimg));
this.pbItem.Image = new System.Drawing.Bitmap(ms);
ms.Close();
}
DataConnection.Close();
}
}
private void btnOverview_Click(object sender, EventArgs e)
{
this.Close();
frmOverview fo = new frmOverview();
fo.Show();
}
private void btnAdjust_Click(object sender, EventArgs e)
{
frmAdjustment fa = new frmAdjustment(this);
frmAdjustment.enteredSKU = txtSKU.Text;
fa.Show();
}
}
frmAdjustmentあなたはこの行を変更する必要が
public partial class frmAdjustment : Form
{
frmAmendStock _main;
OleDbConnection connect = new OleDbConnection();
public string enteredSKU { get; set; }
public frmAdjustment(frmAmendStock main)
{
InitializeComponent();
_main = main;
}
それがうまくいった、ありがとう:D – iiAaronXiX