Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: 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
Edited 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
0 OriginalGriff 377
1 Nirav Prabtani 284
2 Richard Deeming 190
3 _Amy 170
4 Mehdi Gholam 140
0 Nirav Prabtani 265
1 OriginalGriff 177
2 _Amy 170
3 Mehdi Gholam 105
4 Maciej Los 90


Advertise | Privacy | Mobile
Web03 | 2.8.140721.1 | Last Updated 10 Nov 2012
Copyright © CodeProject, 1999-2014
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