You are storing image path in database (column monday_img_slot1) instead of actual image.
Need to convert image into Byte first and then store it in database.
Below is one demo for how to upload Image in database ( table name="images" and "data" column is longblob ,"id" is int,"name" is string type)
Note:you need to use prepared statement to avoid mysql injection.
MySqlConnection con=null;
try
{
string myConnectionString = "server=localhost;database=test;uid=root;pwd=root;";
OpenFileDialog openFileDialog1 = new OpenFileDialog();
openFileDialog1.Filter = "Image files | *.jpg";
if (openFileDialog1.ShowDialog() == DialogResult.OK)
{
con = new MySqlConnection(myConnectionString);
string FileName = openFileDialog1.FileName;
FileStream fs = new FileStream(FileName, FileMode.Open, FileAccess.Read);
BinaryReader br = new BinaryReader(fs);
byte[] ImageData = br.ReadBytes((int)fs.Length);
br.Close();
fs.Close();
string CmdString = "INSERT INTO images(id, name, data) VALUES(@id, @name, @data)";
MySqlCommand cmd = new MySqlCommand(CmdString, con);
cmd.Parameters.Add("@id", MySqlDbType.Int32);
cmd.Parameters.Add("@name", MySqlDbType.VarChar, 45);
cmd.Parameters.Add("@data", MySqlDbType.LongBlob);
cmd.Parameters["@id"].Value = 5;
cmd.Parameters["@name"].Value = textBox1.Text;
cmd.Parameters["@data"].Value = ImageData;
con.Open();
int RowsAffected = cmd.ExecuteNonQuery();
if (RowsAffected > 0)
{
MessageBox.Show("Image saved sucessfully!");
}
}
else
{
MessageBox.Show("Incomplete data!", "", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
finally
{
if (con!=null && con.State == ConnectionState.Open)
{
con.Close();
}
}
In your case before update command ,convert image into byte:
MySqlConnection con=null;
try
{
con = new MySqlConnection(conname);
string captureimg = path;
FileStream fs = new FileStream(captureimg, FileMode.Open, FileAccess.Read);
BinaryReader br = new BinaryReader(fs);
byte[] ImageData = br.ReadBytes((int)fs.Length);
br.Close();
fs.Close();
string CmdString = "Update faculty_attend_record set monday_slot1=@monday_slot1,monday_img_slot1=@monday_img_slot1,monday_class_slot1=@monday_class_slot1,monday_room_slot1=@monday_room_slot1 where idfaculty=@idfaculty";
MySqlCommand cmd = new MySqlCommand(CmdString, con);
cmd.Parameters.Add("@monday_slot1", MySqlDbType.VarChar, 50);
cmd.Parameters.Add("@monday_img_slot1", MySqlDbType.LongBlob);
cmd.Parameters.Add("@monday_class_slot1", MySqlDbType.VarChar, 50);
cmd.Parameters.Add("@monday_room_slot1", MySqlDbType.VarChar, 50);
cmd.Parameters.Add("@idfaculty", MySqlDbType.VarChar, 50);
cmd.Parameters["@monday_slot1"].Value = "present";
cmd.Parameters["@monday_img_slot1"].Value = ImageData;
cmd.Parameters["@monday_class_slot1"].Value = classname1.Text;
cmd.Parameters["@monday_room_slot1"].Value = RoomNo1.Text;
cmd.Parameters["@idfaculty"].Value = idfaculty;
con.Open();
int RowsAffected = cmd.ExecuteNonQuery();
if (RowsAffected > 0)
{
MessageBox.Show("Image saved sucessfully!");
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
finally
{
if (con!=null && con.State == ConnectionState.Open)
{
con.Close();
}
}
Note: As I don't know fully datatype of columns present in your table, I assume it all string and one longbolb so you do modification according to your requirement.