我正在开发成绩管理系统。我只会问如何获取列的所有数据并将其放入选定的Labels并将其保存到新数据库中
如果有其他方法或建议,我将很感激-我只是新来的人。
这是我的代码
string sql = "select distinct * from tbl_TestGrade where ID = '" + textBox1 .Text+ "' ";
cm = new SqlCommand(sql, cn);
dr = cm.ExecuteReader();
while (dr.Read())
{
// I want to get all the data of the student subjects by id
}
dr.Close();
答案 0 :(得分:0)
您可以使用DataReader.Item [string columnName]属性获取特定列的值。遍历阅读器时,尝试将数据存储在列表中。
List<object> studentData = new List<object>();
while(dr.Read())
{
studentData.Add(dr.Item["Subjects"]);
}