0

private void timer1_Tick(object sender, EventArgs e) {

      //  try
       // {
            BarcodeReader reader = new BarcodeReader();
            Result result = reader.Decode((Bitmap)scanQRIMAGE.Image);
            string decoded = result.ToString().Trim();
            ID_text.Text = decoded;


           if (decoded != null)
          {
              
                con.Open();
               
                MySqlCommand coman = new MySqlCommand();
                coman.Connection = con;
                coman.CommandText = " select * from  hopetestdb  where id Like'%" + ID_text.Text + "%'";
                MySqlDataReader dr = coman.ExecuteReader();
                dr.Read();
                 
                if (dr.HasRows)
                {

                    ID_text.Text = dr["id"].ToString();
                   tb_Fname.Text = dr["Firstname"].ToString();
                    tb_Lastname.Text = dr["Lastname"].ToString();
                    tb_Role.Text = dr["GymRole"].ToString();
                   
                    byte[] img = ((byte[])dr["Photo"]);
                    MemoryStream ms = new MemoryStream(img);
                    IMAGEperson.Image = Image.FromStream(ms);





                }

                con.Close();

even it detect something this always happen and sometimes wrong data will appear result was null i check if i have wrong in the youtube that i watch but nothing wrong

  • You named the exception you get(good) but not where it happens in your code. For that you should try to debug your code and if you then now where it happens tell us. Or if you then see the problem yourself answer your own question. – Ralf Dec 08 '22 at 09:33
  • We need to know which line is throwing the error. If I had to guess, I'd say that one of your dr[".."] values is null and so you're trying to call `ToString()` on null, which is not going to work. You might fix this problem with a question mark, as in `dr["..."]?.ToString()`. Still, it's best to know which line is the offender - having the full stacktrace would point you to the problem. – Vic F Dec 08 '22 at 14:09

0 Answers0