Click here to Skip to main content
15,846,342 members
Please Sign up or sign in to vote.
1.80/5 (2 votes)
See more:
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
Posted
Comments
[no name] 26-Jun-14 9:41am    
You need to read your image from the database as a byte array just like you saved it.
Member 10717094 26-Jun-14 9:53am    
Where should i trigger that from loading it in datagridview or when loading it in picture box can u give example? Ty for ur time
[no name] 26-Jun-14 10:15am    
Well I would do it when I read if from my database before trying to use it.
Member 10717094 26-Jun-14 10:30am    
Thanks for the hint
Sergey Alexandrovich Kryukov 26-Jun-14 13:42pm    
Why PictureBox? Why not image? The whole thing looks like one big abuse.
—SA

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900