Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Please let me know if this works:</p> <pre><code>private void button7_Click(object sender, EventArgs e) { ProductDetails.Items.Clear(); SqlConnection con = new SqlConnection(@"server=xxx-PC; database= sample; integrated security= true"); SqlCommand cmd = new SqlCommand("select * from tblproduct where prodname like @name;", con); cmd.Parameters.AddWithValue(textBox1.Text.Trim() + "%"); SqlDataAdapter da = new SqlDataAdapter(cmd); DataTable dt = new DataTable(); try { con.Open(); da.Fill(dt); } catch (Exception e) { //exception handling here } finally { con.Close(); } foreach(DataRow dr in dt.Rows) { byte[]imgg =(byte[])dr["image"]; if(imgg==null || imgg.length &lt;= 0) pictureBox1.Image= null; else { pictureBox1.Image = ByteToImage(imgg); } ProductDetails.Items.Add(dr[0].ToString() + " \t" + dr[1].ToString() + "\t" + dr[2].ToString() + dr[3].ToString()); } } // https://stackoverflow.com/questions/9576868/how-to-put-image-in-a-picture-box-from-a-byte-in-c-sharp public static Bitmap ByteToImage(byte[] blob) { MemoryStream mStream = new MemoryStream(); byte[] pData = blob; mStream.Write(pData, 0, Convert.ToInt32(pData.Length)); Bitmap bm = new Bitmap(mStream, false); mStream.Dispose(); return bm; } </code></pre> <p>You can also use a <code>using</code> block with the <code>SqlConnection</code> as in <a href="https://stackoverflow.com/questions/4717789/in-a-using-block-is-a-sqlconnection-closed-on-return-or-exception">this SO question</a>. Also please note that it is better to <strong>not</strong> use <code>Select * from ...</code> but name the columns. You can read more about it on these links:</p> <ul> <li><a href="http://satheeqhassan.blogspot.nl/2012/10/why-is-bad-practice-in-t-sql_3.html" rel="nofollow noreferrer">http://satheeqhassan.blogspot.nl/2012/10/why-is-bad-practice-in-t-sql_3.html</a></li> <li><a href="http://www.toadworld.com/platforms/sql-server/b/weblog/archive/2012/07/27/how-to-prevent-select-the-evil-way.aspx" rel="nofollow noreferrer">http://www.toadworld.com/platforms/sql-server/b/weblog/archive/2012/07/27/how-to-prevent-select-the-evil-way.aspx</a></li> </ul>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload