3
Answers

Read the last record...

Israel

Israel

9y
730
1
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)