Click here to Skip to main content
12,458,167 members (53,994 online)
Rate this:
 
Please Sign up or sign in to vote.
See more: C# C#4.0
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:
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 9-Nov-12 15:43pm
Updated 9-Nov-12 21:46pm
v2

1 solution

Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 1

use readerscore.GetString("MatricNo") or readerscore.GetString(2) instead of readerscore["MatricNo"].
  Permalink  

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

  Print Answers RSS
Top Experts
Last 24hrsThis month


Advertise | Privacy | Mobile
Web01 | 2.8.160826.1 | Last Updated 10 Nov 2012
Copyright © CodeProject, 1999-2016
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100