Israel

Israel

  • 702
  • 1.3k
  • 216.4k

Read the last record...

Feb 19 2015 11:46 AM
Hi!

I need to read only the last record bringing this data here (lblTotalBancoCons.Text). But I receive this error: Object cannot be cast from DBNull to other types.

            DataTable dt = new DataTable();
            OleDbDataAdapter da = new OleDbDataAdapter(cmd);
            da.Fill(dt);

            conn.Close();
            dvgBancoCons.DataSource = dt;

            ///////////////////////////////////

            int sum = 0;
            for (int i = 0; i < dvgBancoCons.Rows.Count; ++i)
            {
                sum += Convert.ToInt32(dvgBancoCons.Rows[i].Cells[10].Value);
                lblTotalBancoCons.Text = " " + sum.ToString();

 dvgBancoCons.CurrentCell = dvgBancoCons.Rows[dvgBancoCons.Rows.Count - 1].Cells[0];

Answers (3)