When I tried to save without an image or picture, I got the error "Empty path name is not legal", but when I saved with an image attached in Picturebox, there was no problem.
This is my Code.
private void btnSave_Click(object sender, EventArgs e) { if (txtAcctno.Text == "") MessageBox.Show("Please Input Account No."); else if (txtLastname.Text == "") MessageBox.Show("Please Input Lastname."); else if (txtFirstname.Text == "") MessageBox.Show("Please Input Firstname."); else if (txtTIN.Text == "") MessageBox.Show("Please Input TIN."); else if (txtAddress.Text == "") MessageBox.Show("Please Input Address."); else { using (OleDbConnection con = new OleDbConnection(connectionString)) { cmd = new OleDbCommand("Insert into tbl_idmonitoring (AcctNo, Lastname, Firstname, MI, Address, IDStatus, MemStatus, TIN, DateRelease, Picture)values(@AcctNo, @Lastname, @Firstname, @MI, @Address, @IDStatus, @MemStatus, @TIN, @DateRelease, @Picture) ", con); con.Open(); string path = ofd.FileName; Byte[] imageData; imageData = System.IO.File.ReadAllBytes(@path); "Error" cmd.Parameters.AddWithValue("@AcctNo", txtAcctno.Text); cmd.Parameters.AddWithValue("@Lastname", txtLastname.Text); cmd.Parameters.AddWithValue("@Firstname", txtFirstname.Text); cmd.Parameters.AddWithValue("@MI", txtMI.Text); cmd.Parameters.AddWithValue("@Address", txtAddress.Text); cmd.Parameters.AddWithValue("@IDStatus", cmbIDStatus.Text); cmd.Parameters.AddWithValue("@MemStatus", cmbMemStatus.Text); cmd.Parameters.AddWithValue("@TIN", txtTIN.Text); cmd.Parameters.AddWithValue("@DateRelease", dateTimePicker1.Text); cmd.Parameters.AddWithValue("@Picture", imageData); cmd.ExecuteNonQuery(); con.Close(); MessageBox.Show("Data Successfully Saved!"); Clear(); }
}