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);
}
You could report which error is occurring?
– Jeferson Almeida
Indice is out of range. Must be non-negative and smaller than the collection size.
– António Mateta
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? Thisusing
may be wrong, is discarding the object and then using something that was discarded, makes no sense, unless theBitmap
make a copy of the object, not sure it does.– Maniero