1
I’m having an exception problem on my show and I’m not sure how to treat it.
Follow the error image in Datagridview.
private void DGW_solictacao_CellClick(object sender, DataGridViewCellEventArgs e)
{
DataGridViewRow row = this.DGW_solictacao.Rows[e.RowIndex];
this.txt_solicitacao.Text = row.Cells[0].Value.ToString();
this.txt_cliente.Text = row.Cells[1].Value.ToString();
this.txt_Contato.Text = row.Cells[2].Value.ToString();
this.txt_solicitante.Text = row.Cells[3].Value.ToString();
this.txt_representante.Text = row.Cells[4].Value.ToString();
this.txt_atuacao.Text = row.Cells[5].Value.ToString();
this.txt_separador.Text = row.Cells[7].Value.ToString();
this.txt_idcliente.Text = row.Cells[9].Value.ToString();
string strSQL = @"select
SA.OBS
from tbl_SolicitacaoAmostra as SA
where SA.Cod_Solicitacao = '" + txt_solicitacao.Text + "'";
comando = new SqlCommand(strSQL, conm);
try
{
SqlDataAdapter dados = new SqlDataAdapter(comando);
DataTable dtLista = new DataTable();
dados.Fill(dtLista);
if (dtLista.Rows.Count > 0)
{
DataRow dr = dtLista.Rows[0];
txt_observacao.Text = dr[0].ToString();
}
}
catch
{
MessageBox.Show("Não existem dados a serem encontrados");
}
}
You are accessing an index that does not exist in a collection. Without seeing the code causing the error you cannot help anymore.
– Jéf Bueno
You should not treat it, you should correct the programming error in the code. Read comment above.
– Maniero
I put the code in the question
– Junior Guerreiro