Quote:
FrmOps f = new FrmOps();
command.Parameters.Add("@CustomerPhoto", SqlDbType.Image).Value = Main_Classes.CLS_Photos.ImageToByteArray(f.MyPictureBox.Image);
You create a new, empty instance of your form class, and expect it to magically pick up the picture from a completely difference instance of the form.
Your
CumstomerParamerterInsert
method should have no idea about your
FrpOps
form. Instead, you should pass in the picture you want to save as a parameter to this method.
private static void CustomerParamerterInsert(int CustomerID, string CustomerName, string CustomerEmail, string CustomerPhone, bool CustomerStatus, Image CustomerPhoto, SqlCommand command)
{
command.Parameters.Add("@CustomerID", SqlDbType.Int).Value = CustomerID;
command.Parameters.Add("@CustomerName", SqlDbType.NVarChar, 150).Value = CustomerName;
command.Parameters.Add("@CustomerEmail", SqlDbType.NVarChar, 50).Value = CustomerEmail;
command.Parameters.Add("@CustomerPhone", SqlDbType.NVarChar, 10).Value = CustomerPhone;
command.Parameters.Add("@CustomerStatus", SqlDbType.Bit).Value = CustomerStatus;
command.Parameters.Add("@CustomerPhoto", SqlDbType.Image).Value = Main_Classes.CLS_Photos.ImageToByteArray(CustomerPhoto);
}
static public bool InsertCustomer(int CustomerID, string CustomerName, string CustomerEmail, string CustomerPhone, bool CustomerStatus, Image CustomerPhoto)
{
return DBHelper.ExcuteData("Save_Customer", () => CustomerParamerterInsert(CustomerID, CustomerName, CustomerEmail, CustomerPhone, CustomerStatus, CustomerPhoto, DBHelper.command));
}
public interface IOps
{
...
Image CustomerPhoto { get; set; }
}
class OpsModel
{
...
public Image CustomerPhoto { get; set; }
}
public void CusInsert()
{
...
OpsService.InsertCustomer(opsModel.CustomerID, opsModel.CustomerName, opsModel.CustomerEmail, opsModel.CustomerPhone, opsModel.CustomerStatus, opsModel.CustomerPhoto);
...
}
public Image CustomerPhoto
{
get => this.MyPictureBox.Image;
set => this.MyPictureBox.Image = value;
}