Click here to Skip to main content
15,900,589 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Am a new programmer in c# and i want to use the value return in datareader to re-query the database.
This is the part of my code:
C#
string queryscore = "SELECT CourseUnit,Score,MatricNo FROM student_result WHERE CourseCode='" + cmbcoursecode.Text.ToString() + "'";

           SqlCommand cmdscore = new SqlCommand(queryscore, con);

           SqlDataReader readerscore;

           readerscore = cmdscore.ExecuteReader();

           while (readerscore.Read())
           {
               score1 = (int)readerscore["Score"];
               int CourseUnit = (int)readerscore["CourseUnit"];
               if (score1 <= 39)
               {
                   string updateresult = "Update Student_Result SET Grade='" + "F" + "' WHERE MatricNo='" + readerscore["MatricNo"] + "'";
                   SqlCommand cmdupdatescore = new SqlCommand(updateresult, con);
                   cmdupdatescore.ExecuteNonQuery();
                  // MessageBox.Show("F");

               }
Posted
Updated 9-Nov-12 21:46pm
v2

1 solution

use readerscore.GetString("MatricNo") or readerscore.GetString(2) instead of readerscore["MatricNo"].
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900