How to solve errors of these Code?

Asked

Viewed 163 times

0

I’m developing a sales system, using visual Studio 2013 and SQL 2008, for some inconvenience I started using Visual Studio 2012, it turns out I’m having an error. The code is right but when running this shows error, when using Visual Studio 2013 ran normally.

 private void dgv_Artigo_CellDoubleClick(object sender, DataGridViewCellEventArgs e)
        {
            this.txt_ID.Text = dgv_Artigo[0, dgv_Artigo.CurrentRow.Index].Value.ToString();
            this.txt_CodBarra.Text = dgv_Artigo[1, dgv_Artigo.CurrentRow.Index].Value.ToString();
            this.txt_Artigo.Text = dgv_Artigo[2, dgv_Artigo.CurrentRow.Index].Value.ToString();
            this.cb_Categoria.Text = dgv_Artigo[5, dgv_Artigo.CurrentRow.Index].Value.ToString();
            this.cb_TipoArtigo.Text = dgv_Artigo[6, dgv_Artigo.CurrentRow.Index].Value.ToString();

            SqlConnection conexao = new SqlConnection(CN);
            SqlDataAdapter adp = new SqlDataAdapter("SELECT * FROM view_artigo where id_artigo = '" + dgv_Artigo.SelectedRows[0].Cells[4].Value.ToString() + "'", conexao);
            DataTable dt = new DataTable();
            adp.Fill(dt);
            byte[] imagembinaria = (byte[])dt.Rows[0][0];
            Bitmap ima;
            using (MemoryStream ms = new MemoryStream(imagembinaria))
            {
                ima = new Bitmap(ms);
            }
            pt_imagem.Image = ima;

            tabControl1.SelectTab(tabPage1);
        }
  • 3

    You could report which error is occurring?

  • Indice is out of range. Must be non-negative and smaller than the collection size.

  • In which line does it occur? If you have error the code is certainly not right. The fact that it works in some situation only means that the error does not happen in all situations. When it works is coincidence. Where it comes from dgv_Artigo.CurrentRow.Index? apparently what’s wrong with it. Are you sure that the array has at least 7 elements in the first dimension? This using may be wrong, is discarding the object and then using something that was discarded, makes no sense, unless the Bitmap make a copy of the object, not sure it does.

1 answer

1

The minimum version of the framework supported by visual Studio 2012 is 4.5 may be that your project is using 4.5.1 or higher

  • Thanks, for the answer, now yes I understand why on the other my pc that has Visual Studio 2013 was running normally and on this pc that I am currently using is giving error.

  • Friend, mark the answers that helped you please

Browser other questions tagged

You are not signed in. Login or sign up in order to post.