Hello, I get this error: "No data exists for the row/column." at the red section in my code. I am sure my database row i am selecting has data in dr.get..(3) and dr.get...(5)
private void button1_Click(object sender, EventArgs e)
{
int cpnumber = Convert.ToInt32(LastCP.Text);
DateTime cpdate = Convert.ToDateTime(dateTimePicker1.Text);
double position = Convert.ToDouble(PositionTB.Text);
double totalsc = Convert.ToDouble(TscoreTB.Text);
double military = Convert.ToDouble(MilitaryTB.Text);
decimal RP = Convert.ToDecimal(RPhourTB.Text);
cmd = null;
cmd = new OleDbCommand();
MyConnection.OpenMyConnection();
cmd.CommandText = "SELECT * FROM checkpoint WHERE ika_checkpoint_number = 1";
cmd.Connection = MyConnection.con;
OleDbDataReader st = cmd.ExecuteReader();
if (st.Read())
{
cmd = null;
cmd = new OleDbCommand();
cmd.CommandText = "Select * from checkpoint where ID=(select max(ID) from checkpoint)";
cmd.Connection = MyConnection.con;
OleDbDataReader dr = cmd.ExecuteReader();
double lastposition = Convert.ToDouble(dr.GetDouble(3));
double lastscore = Convert.ToDouble(dr.GetDouble(5));
double poschange = position - lastposition;
double scorechange = totalsc - lastscore;
cmd = null;
cmd = new OleDbCommand();
cmd.Connection = MyConnection.con;
cmd.CommandText = "INSERT INTO checkpoint ([ika_checkpoint_number], [ika_checkpoint_date], [ika_position], [ika_position_change], [ika_total_score], [ika_score_growth], [ika_military], [ika_research]) VALUES (@cpnum, @cpdate, @pos, @poschange, @cpscore, @cpscorechange, @cpmilitary, @cprp)";
cmd.Parameters.AddRange(new OleDbParameter[]
{
new OleDbParameter("@cpnum", cpnumber),
new OleDbParameter("@cpdate", cpdate),
new OleDbParameter("@pos", position),
new OleDbParameter("@poschange", poschange),
new OleDbParameter("@cpscore", totalsc),
new OleDbParameter("@cpscorechange", scorechange),
new OleDbParameter("@cpmilitary", military),
new OleDbParameter("@cprp", RP),
});
int count = cmd.ExecuteNonQuery();
MyConnection.CloseMyConnection();
if (count > 0)
{
this.Hide();
IkariamDataForm newform = (IkariamDataForm)Application.OpenForms["IkariamDataForm"];
newform.FillAchievementsGrid();
newform.FillCheckPointGrid(); ;
this.Close();
}
}
}