Click here to Skip to main content
Sign Up to vote bad
good
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:43
Edited 9 Nov '12 - 21:46


1 solution

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
Your Filters
Interested
Ignored
     
0 Sergey Alexandrovich Kryukov 278
1 Mohammed Hameed 268
2 OriginalGriff 236
3 Mayur_Panchal 153
4 Dave Kreskowiak 125
0 Sergey Alexandrovich Kryukov 8,171
1 OriginalGriff 6,236
2 CPallini 3,482
3 Rohan Leuva 2,703
4 Maciej Los 2,234


Advertise | Privacy | Mobile
Web04 | 2.6.130516.1 | Last Updated 10 Nov 2012
Copyright © CodeProject, 1999-2013
All Rights Reserved. Terms of Use
Layout: fixed | fluid