if (ImageByte.Value = null) { MessageBox.Show("This is max of ur contacts"); } else { string sql = "select Attachments.FileData from Contacts where ID =" + lbl19.Text;//Attachments.FileData OleDbCommand vcom = new OleDbCommand(sql, cn); ImageByte = (byte[])vcom.ExecuteScalar(); //contains 20 extra bytes MemoryStream MemStream = new MemoryStream(ImageByte.Skip(20).ToArray()); //Read bytes starting at position 20 Image image = Image.FromStream(MemStream); //Will work now pictureBox1.Image = image; }
string sql = "select Attachments.FileData from Contacts where ID =" + lbl19.Text;
const string sql = "select Attachments.FileData from Contacts where ID = ?"; using (OleDbCommand vcom = new OleDbCommand(sql, cn)) { vcom.Parameters.AddWithValue("ID", lbl19.Text); ImageByte = (byte[])vcom.ExecuteScalar(); }
lbl42
lblTheAnswer
if (ImageByte.Value = null) // *** this sets ImageByte.Value to null. // it should be if (ImageByte.Value == null) // equality test, not assignment
if (ImageByte.Value = null)
==
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)