使用Datareader值查询数据库 [英] Using Datareader value to query database
本文介绍了使用Datareader值查询数据库的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我是C#的新程序员,我想使用datareader中的return值重新查询数据库.
这是我的代码的一部分:
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");
}
推荐答案
使用 readerscore.GetString("MatricNo")或 readerscore.GetString(2)而不是readerscore ["MatricNo"].
use readerscore.GetString("MatricNo") or readerscore.GetString(2) instead of readerscore["MatricNo"].
这篇关于使用Datareader值查询数据库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文