Je souhaite récupérer les données de la base de données. Quand je modifie mon code pour l'image son paramètre d'affichage n'est pas valide.Paramètre non valide
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());
}
}
AJOUTÉE de OP de Commentaire
pour le chargement i utiliser ce code
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);
Quelle ligne L'erreur se produit sur? – Tim
vous devriez vraiment jeter un coup d'oeil à [sqlParameter] (http://msdn.microsoft.com/fr-ca/library/system.data.sqlclient.sqlparameter%28v=vs.110%29.aspx). Votre code est faible à [Injection sql] (http://en.wikipedia.org/wiki/SQL_injection) –
Possible dupliquer http://stackoverflow.com/questions/629955/parameter-not-valid-exception-loading-system -drawing-image erreur –