Beginner here, I'm trying to update the image and the image's name from a different form and it's not updating. Also it doesn't give any errors. Is there something wrong in the code?
Form 2. this is where i update
private void btnStockEdit_Click_1(object sender, EventArgs e)
{
try
{
sqlCon.Open();
string qry = "Update SMStocksTb Set SmStockImgName=@SmStockImgName,SmStockImage=@SmStockImage where SmStockId=@SmStockId";
SqlCommand cmd = new SqlCommand(qry, sqlCon);
cmd.Parameters.AddWithValue("@SmStockId", SmStockId);
cmd.Parameters.AddWithValue("@SmStockImgName", txtUPImgName.Text);
cmd.Parameters.AddWithValue("@SmStockImage", Savephoto());
cmd.ExecuteNonQuery();
sqlCon.Close();
MessageBox.Show("Update Successfully","Updated",MessageBoxButtons.OK,MessageBoxIcon.Information);
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}
private byte[] Savephoto()
{
MemoryStream ms = new MemoryStream();
pbxUpdateImg.Image.Save(ms, pbxUpdateImg.Image.RawFormat);
return ms.GetBuffer();
}
**Form1 ** this is where i open form 2 after selecting a row in datagrid
private void btnStockEdit_Click(object sender, EventArgs e)
{
SMStockUpdateForm cfrmStockUpdateForm = new SMStockUpdateForm();
try
{
if (StockListDG.CurrentRow.Index != -1)
{
SmStockId = Convert.ToInt32(StockListDG.CurrentRow.Cells[0].Value.ToString());
cfrmStockUpdateForm.txtUPImgName.Text = StockListDG.CurrentRow.Cells[11].Value.ToString();
byte[] ImageArray = (byte[])StockListDG.CurrentRow.Cells[12].Value;
if (ImageArray.Length == 0)
cfrmStockUpdateForm.pbxUpdateImg.Image = DefaultImage;
else
{
ImageByteArray = ImageArray;
cfrmStockUpdateForm.pbxUpdateImg.Image = Image.FromStream(new MemoryStream(ImageArray));
}
}
}
catch (Exception ex)
{
}
cfrmStockUpdateForm.ShowDialog(this);
if (isWindowOpen == false)
{
this.ParentForm.Opacity = 100;
}
}