Able to insert image in form and saving also but, its showing error when am edit/update image and not able to save with update.
When I remove only image code then both Insert and update/edit is working fine.
Can any please help me out on that image error. I will show you code C# below.
C# insert code: (This was working fine)
C# Update code: (its showing error, see Red color error)
When I remove only image code then both Insert and update/edit is working fine.
Can any please help me out on that image error. I will show you code C# below.
C# insert code: (This was working fine)
C#:
public void insert()
{
SqlConnection connection = new SqlConnection(dbFunctions.connectionstring);
try
{
MemoryStream stream;
connection.Open();
SqlCommand command = new SqlCommand {
Connection = connection,
CommandType = CommandType.StoredProcedure,
CommandText = "Pr_Insert_CustomerMaster"
};
command.Parameters.Add("@CM_Customer_name", SqlDbType.VarChar).Value = this.CM_Customer_name.Text.ToString();
command.Parameters.Add("@CM_Address", SqlDbType.VarChar).Value = this.CM_Address.Text.ToString();
command.Parameters.Add("@CM_Others", SqlDbType.VarChar).Value = this.CM_Others.Text.ToString();
command.Parameters.Add("@CM_PhoneNo", SqlDbType.VarChar).Value = this.CM_PhoneNo.Text.ToString();
command.Parameters.Add("@CM_City", SqlDbType.VarChar).Value = this.CM_City.Text.ToString();
byte[] buffer = null;
try
{
stream = new MemoryStream();
this.Person.Image.Save(stream, ImageFormat.Jpeg);
buffer = stream.GetBuffer();
}
catch
{
}
command.Parameters.Add("@CM_Image", SqlDbType.Image).Value = buffer;
byte[] buffer2 = null;
try
{
stream = new MemoryStream();
this.Proof.Image.Save(stream, ImageFormat.Jpeg);
buffer2 = stream.GetBuffer();
}
catch
{
}
command.Parameters.Add("@CM_Proof", SqlDbType.Image).Value = buffer2;
command.Parameters.Add("@CM_Lodge", SqlDbType.VarChar).Value = dbFunctions.Lodge;
command.Parameters.Add("@CM_GSTNo", SqlDbType.VarChar).Value = this.txt_GSTNo.Text.ToString();
if (this.CM_GuestCompanyName.Text == "")
{
command.Parameters.Add("@CM_Guest_company_name", SqlDbType.VarChar).Value = "0";
}
else
{
command.Parameters.Add("@CM_Guest_company_name", SqlDbType.VarChar).Value = this.CM_GuestCompanyName.SelectedValue.ToString();
}
command.Parameters.Add("@CM_PassPort_No", SqlDbType.VarChar).Value = this.CM_PassPort_No.Text.ToString();
command.Parameters.Add("@CM_Visa_No", SqlDbType.VarChar).Value = this.CM_Visa_No.Text.ToString();
command.Parameters.Add("@CM_Issue_Date", SqlDbType.VarChar).Value = this.CM_Issue_Date.Text.ToString();
command.Parameters.Add("@CM_Expire_Date", SqlDbType.VarChar).Value = this.CM_Expire_Date.Text.ToString();
command.Parameters.Add("@CM_Place", SqlDbType.VarChar).Value = this.CM_IssuePlace.Text.ToString();
command.Parameters.Add("@CM_Country", SqlDbType.VarChar).Value = this.CM_Country.Text.ToString();
command.Parameters.Add("@CM_Visa_IssDate", SqlDbType.VarChar).Value = this.CM_Visa_IssDate.Text.ToString();
command.Parameters.Add("@CM_Visa_Expiry_Date", SqlDbType.VarChar).Value = this.CM_Visa_IssDate.Text.ToString();
command.Parameters.Add("@Proof_Name", SqlDbType.VarChar).Value = this.Proof_Name.Text.ToString();
command.Parameters.Add("@Proof_Id", SqlDbType.VarChar).Value = this.Proof_Id.Text.ToString();
command.ExecuteNonQuery();
MessageBox.Show("Details Saved Successfully ", "Sucess", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
this.Clear();
this.display();
}
catch (Exception exception)
{
dbFunctions.Logs(exception.Message, dbFunctions.username);
MessageBox.Show(exception.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Hand);
}
}
C# Update code: (its showing error, see Red color error)
C#:
public void Update()
{
SqlConnection connection = new SqlConnection(dbFunctions.connectionstring);
try
{
MemoryStream stream;
connection.Open();
SqlCommand command = new SqlCommand {
Connection = connection,
CommandType = CommandType.StoredProcedure,
CommandText = "Pr_Update_CustomerMaster"
};
command.Parameters.Add("@CM_Customer_name", SqlDbType.VarChar).Value = this.CM_Customer_name.Text.ToString();
command.Parameters.Add("@CM_Address", SqlDbType.VarChar).Value = this.CM_Address.Text.ToString();
command.Parameters.Add("@CM_Others", SqlDbType.VarChar).Value = this.CM_Others.Text.ToString();
command.Parameters.Add("@CM_PhoneNo", SqlDbType.VarChar).Value = this.CM_PhoneNo.Text.ToString();
command.Parameters.Add("@CM_City", SqlDbType.VarChar).Value = this.CM_City.Text.ToString();
byte[] buffer = null;
try
{
stream = new MemoryStream();
this.Person.Image.Save(stream, ImageFormat.Jpeg);
buffer = stream.GetBuffer();
}
catch
{
}
command.Parameters.Add("@CM_Image", SqlDbType.Image).Value = buffer;
byte[] buffer2 = null;
try
{
stream = new MemoryStream();
this.Proof.Image.Save(stream, ImageFormat.Jpeg);
buffer2 = stream.GetBuffer();
}
catch
{
}
command.Parameters.Add("@CM_Proof", SqlDbType.Image).Value = buffer2;
command.Parameters.Add("@CM_Lodge", SqlDbType.VarChar).Value = dbFunctions.Lodge;
command.Parameters.Add("@CM_GSTNo", SqlDbType.VarChar).Value = this.txt_GSTNo.Text.ToString();
if (this.CM_GuestCompanyName.Text == "")
{
command.Parameters.Add("@CM_Guest_company_name", SqlDbType.VarChar).Value = "0";
}
else
{
command.Parameters.Add("@CM_Guest_company_name", SqlDbType.VarChar).Value = this.CM_GuestCompanyName.SelectedValue.ToString();
}
command.Parameters.Add("@CM_PassPort_No", SqlDbType.VarChar).Value = this.CM_PassPort_No.Text.ToString();
command.Parameters.Add("@CM_Visa_No", SqlDbType.VarChar).Value = this.CM_Visa_No.Text.ToString();
command.Parameters.Add("@CM_Issue_Date", SqlDbType.VarChar).Value = this.CM_Issue_Date.Text.ToString();
command.Parameters.Add("@CM_Expire_Date", SqlDbType.VarChar).Value = this.CM_Expire_Date.Text.ToString();
command.Parameters.Add("@CM_Place", SqlDbType.VarChar).Value = this.CM_IssuePlace.Text.ToString();
command.Parameters.Add("@CM_Country", SqlDbType.VarChar).Value = this.CM_Country.Text.ToString();
command.Parameters.Add("@CM_Visa_IssDate", SqlDbType.VarChar).Value = this.CM_Visa_IssDate.Text.ToString();
command.Parameters.Add("@CM_Visa_Expiry_Date", SqlDbType.VarChar).Value = this.CM_Visa_IssDate.Text.ToString();
command.Parameters.Add("@Proof_Name", SqlDbType.VarChar).Value = this.Proof_Name.Text.ToString();
command.Parameters.Add("@Proof_Id", SqlDbType.VarChar).Value = this.Proof_Id.Text.ToString();
command.ExecuteNonQuery();
MessageBox.Show("Details Saved Successfully ", "Sucess", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
this.Clear();
this.display();
}
catch (Exception exception)
{
dbFunctions.Logs(exception.Message, dbFunctions.username);
MessageBox.Show(exception.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Hand);
}
}
Last edited by a moderator: