Gabriel olayinka

Gabriel olayinka

  • NA
  • 119
  • 4.2k

can't save to database

Mar 31 2018 7:31 AM
i have a 2 tables in a database..... i'm retrieving record from one table,  the insert the record into another table after changing some of the contents..... here is my code
 
void CreateRecord()
{
try
{
con.Open();
String sql = "SELECT STUD_ID, FNAME,LNAME,UNIQUE_REF,CLASSRM_ID from STUDENTS where CLASSRM_ID= '" + CLASSROOM_ID + "'";
SqlCommand cmd = new SqlCommand(sql, con);
SqlDataReader rdr = cmd.ExecuteReader(CommandBehavior.CloseConnection);
while (rdr.Read() )
{
STUD_ID = (int)rdr[0] ;
STUD_NAME =( rdr[1] + " " + rdr[2]).ToString();
UNIQUE_REF = rdr[3].ToString();
CLASSRM_ID = (int)rdr[4];
getSelectedSubjectID();
//this is the part that does the saving and its working fine 
SaveAssessmentTemp();
}
}
finally
{
con.Close();
}
}//end  CreateRecord
 
my problem is that ..... the last record in the (first table) which was retrieved into the datareader (rdr) is been saved twice..... how do i handle this? 
 

Answers (2)