简体   繁体   中英

How to get value of columns and put it into label C# & SQL Server

I'm working on a Grade Management System. I'll just ask how do I get all the data of columns and put it into selected Labels and save it to new database

If there's another way or advice I'll be thankful - I'm just new here.

This is my code

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();

You can get the value of specific column with the DataReader.Item[string columnName] property. Try storing the data in a list while looping through the reader.

List<object> studentData = new List<object>();    

while(dr.Read())
{
    studentData.Add(dr.Item["Subjects"]);
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM