THIS IS HOW I SAVED MY IMAGE
private void btnSave_Click(object sender, EventArgs e)
{
MemoryStream ms = new MemoryStream();
pictureBox1.Image.Save(ms, System.Drawing.Imaging.ImageFormat.Jpeg);
byte[] photo_aray = new byte[ms.Length];
ms.Read(photo_aray, 0, photo_aray.Length);
SqlConnection con = new SqlConnection(@"server=.\SQLEXPRESS; database=test; Integrated Security=SSPI");
con.Open();
string query = "insert into patient(name,remarks,result2) values(@name,@remarks,@result2)";
SqlCommand cmd = new SqlCommand(query, con);
cmd.Parameters.AddWithValue("@name", txtName.Text);
cmd.Parameters.AddWithValue("@remarks", txtRemarks.Text);
cmd.Parameters.AddWithValue("@result2", photo_aray);
cmd.ExecuteNonQuery();
MessageBox.Show("Ayos !");
con.Close();
txtName.Text = string.Empty;
txtRemarks.Text = string.Empty;
pictureBox1.Image = null;
loadData();
}
THIS IS HOW I LOAD MY GRIDVIEW (dbase bounded)
private void loadData()
{
SqlConnection con = new SqlConnection(@"server=.\SQLEXPRESS; database=test; Integrated Security=SSPI");
con.Open();
string query = "select * from patient";
SqlDataAdapter da = new SqlDataAdapter(query, con);
DataTable dt = new DataTable();
da.Fill(dt);
dataGridView1.DataSource = dt;
dataGridView1.SelectionMode = DataGridViewSelectionMode.FullRowSelect;
dataGridView1.Columns[3].Visible = false;
dataGridView1.Columns[4].Visible = false;
con.Close();
}
THIS IS HOW I LOAD GRID CONTENT TO TEXTBOX AND PICTUREBOX
private void btnLoad_Click(object sender, EventArgs e)
{
int i;
i = dataGridView1.SelectedCells[0].RowIndex;
labelID.Text = dataGridView1.Rows[i].Cells[0].Value.ToString();
txtName.Text = dataGridView1.Rows[i].Cells[1].Value.ToString();
txtRemarks.Text = dataGridView1.Rows[i].Cells[2].Value.ToString();
pictureBox1.Image = Image.FromFile(dataGridView1.Rows[i].Cells[4].Value.ToString());
ERROR IS System.Byte[]
system.io.filenotfoundexception
{"System.Byte[]":null}
}
Thanks in Advance