Israel

Israel

  • 693
  • 1.3k
  • 219.4k

Doesnt search the right data from Database

Apr 27 2019 8:30 AM
Hi,
 
I have data into my DB (five records). When I search for example the number "3" its sturk and give the error message: the parameter it's not valide. Curiosly all number out of numbers inside of my DB (1,2,3,4,5) its says "Data not find".
  1. private void button2_Click(object sender, EventArgs e)  
  2. {  
  3. conn.Open();  
  4. string sqlQuery = "select * from test where id ='" + textID.Text + "'";  
  5. cmd = new SqlCommand(sqlQuery, conn);  
  6. SqlDataReader DataRead = cmd.ExecuteReader();  
  7. DataRead.Read();  
  8. if (DataRead.HasRows)  
  9. {  
  10. textName.Text = DataRead[1].ToString();  
  11. byte[] img = ((byte[])DataRead[2]);  
  12. if (img == null)  
  13. {  
  14. pictureBox1.Image = null;  
  15. }  
  16. else  
  17. {  
  18. MemoryStream mstream = new MemoryStream(img);  
  19. pictureBox1.Image = Image.FromStream(mstream); // Its sturk here on this line  
  20. }  
  21. }  
  22. else  
  23. {  
  24. MessageBox.Show("Data not find");  
  25. }  
  26. conn.Close();  
  27. }  

Answers (8)