//EDIT statement
if (MessageBox.Show("Are you sure you want to Update this Existing Record??", "Update existing item", MessageBoxButtons.YesNo) == DialogResult.Yes)
{
try
{
if (textBox2.Text.Length > 0 && textBox11.Text.Length > 0)
{
string FileName = textBox11.Text;
byte[] ImageData;
fs = new FileStream(FileName, FileMode.Open, FileAccess.Read);
br = new BinaryReader(fs);
ImageData = br.ReadBytes((int)fs.Length);
//String ImageData1 = Convert.ToBase64String(ImageData);
br.Close();
fs.Close();
string CmdString = "UPDATE capilpilfile SET First = '" + textBox2.Text +
"', Middle = '" + textBox3.Text + "', Last = '" + textBox4.Text + "', Amount = '" +
textBox5.Text + "', receipt = '" + textBox6.Text + "', Address = '" + textBox7.Text +
"', TDate = '" + textBox8.Text + "', GraveID = '" + textBox9.Text + "', image = '" + ImageData +
"', handler = '" + textBox10.Text + "', imgloc = '" + textBox11.Text + "' where ID = " + id.ToString() + ";";
cmd = new MySqlCommand(CmdString, con);
cmd.Parameters.Add("@First", MySqlDbType.VarChar, 30);
cmd.Parameters.Add("@Middle", MySqlDbType.VarChar, 10);
cmd.Parameters.Add("@Last", MySqlDbType.VarChar, 30);
cmd.Parameters.Add("@Amount", MySqlDbType.VarChar, 30);
cmd.Parameters.Add("@Receipt", MySqlDbType.VarChar, 30);
cmd.Parameters.Add("@Address", MySqlDbType.VarChar, 100);
cmd.Parameters.Add("@TDate", MySqlDbType.VarChar, 30);
cmd.Parameters.Add("@GraveID", MySqlDbType.VarChar, 30);
cmd.Parameters.Add("@image", MySqlDbType.LongBlob, 50);
cmd.Parameters.Add("@handler", MySqlDbType.VarChar, 20);
cmd.Parameters.Add("@imgloc", MySqlDbType.VarChar, 200);
cmd.Parameters["@First"].Value = textBox2.Text;
cmd.Parameters["@Middle"].Value = textBox3.Text;
cmd.Parameters["@Last"].Value = textBox4.Text;
cmd.Parameters["@Amount"].Value = textBox5.Text;
cmd.Parameters["@Receipt"].Value = textBox6.Text;
cmd.Parameters["@Address"].Value = textBox7.Text;
cmd.Parameters["@TDate"].Value = textBox8.Text;
cmd.Parameters["@GraveID"].Value = textBox9.Text;
cmd.Parameters["@image"].Value = ImageData;
cmd.Parameters["@handler"].Value = textBox10.Text;
cmd.Parameters["@imgloc"].Value = textBox11.Text;
con.Open();
int RowsAffected = cmd.ExecuteNonQuery();
if (RowsAffected > 0)
{
MessageBox.Show("One record successfully UPDATED!...");
}
con.Close();
}
else
{
MessageBox.Show("Incomplete data!", "", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
finally
{
if (con.State == ConnectionState.Open)
{
con.Close();
}
}
Loading
Joginder BangerPosted Nov 13, 2014, 12:50 AM
For Example: I assume in your records have one Hundreds (100) Records you need a one Hundreds Rows. if your image size around 1mb and after the convert this image in byte take a size 1.5 mb your database size is cross the size and performance goes down.
So I advice you save only path in the database. your image save any folder.
OpenFileDialog opFile = new OpenFileDialog();
opFile.Title = "Select a Image";
opFile.Filter = "jpg files (*.jpg)|*.jpg|All files (*.*)|*.*";
string appPath = Path.GetDirectoryName(Application.ExecutablePath) + @"\ProImages\"; if (Directory.Exists(appPath) == false)
{
Directory.CreateDirectory(appPath);
}
if (opFile.ShowDialog() == DialogResult.OK)
{
try
{
string iName = opFile.SafeFileName; string filepath = opFile.FileName;
File.Copy(filepath, appPath + iName);
picProduct.Image = new Bitmap(opFile.OpenFile());
}
catch (Exception exp)
{
MessageBox.Show("Unable to open file " + exp.Message);
}
}
else { opFile.Dispose(); }
I hope you are understand point of my view.