我想從數據庫中檢索數據。當我改變我的代碼來使其顯示參數無效時。參數無效
private void button7_Click(object sender, EventArgs e)
{
ProductDetails.Items.Clear();
SqlConnection con = new SqlConnection(@"server=xxx-PC; database= sample; integrated security= true");
con.Open();
SqlCommand cmd = new SqlCommand("select * from tblproduct where prodname like '" + textBox1.Text + "%';", con);
SqlDataReader dr = cmd.ExecuteReader();
while (dr.Read())
{
byte[]imgg =(byte[])(dr["image"]);
if(imgg==null)
pictureBox1.Image= null;
else
{ //i m not getting error it says parameter not valid below//
MemoryStream mstream = new MemoryStream(imgg);
pictureBox1.Image = System.Drawing.Image.FromStream(mstream);
}
ProductDetails.Items.Add(dr[0].ToString() + " \t" + dr[1].ToString() + "\t" + dr[2].ToString()+ dr[3].ToString());
}
}
加入得自OP的評論
加載我用這個代碼
byte[] imagebt = null;
FileStream fstream = new FileStream(this.textBox5.Text, FileMode.Open, FileAccess.Read);
BinaryReader br = new BinaryReader(fstream);
imagebt = br.ReadBytes((int)fstream.Length);
沒有錯誤發生在哪一行? – Tim
你應該看看[sqlParameter](http://msdn.microsoft.com/en-ca/library/system.data.sqlclient.sqlparameter%28v=vs.110%29.aspx)。你的代碼對於[sql注入](http://en.wikipedia.org/wiki/SQL_injection) –
可能是重複http://stackoverflow.com/questions/629955/parameter-not-valid-exception-loading-system -drawing-image –