从数据库中查询数据后,我使用数据读取器填充数组。如下。
connection.Open();
System.Data.SqlClient.SqlDataReader reader = command.ExecuteReader();
reader.Read();
_firstname = reader[0].ToString();
_Year = reader[1].ToString();
_coursename = reader[2].ToString();
_credits = reader[3].ToString();
_mark = reader[4].ToString();
_firstname2 = reader[5].ToString();
reader.Close();
我但结果显示如下
1 - Sam Bons
2- 2012
3- DDD
4- 3
5- 80
如何执行循环以从数据库中获取所有结果并将其打印出来?
谢谢你
我这样做了谢谢你,安
result = string.Empty;
int counter = 1;
while (reader.Read())
{
_firstname = reader[0].ToString();
_Year = reader[1].ToString();
_coursename = reader[2].ToString();
_credits = reader[3].ToString();
_mark = reader[4].ToString();
result += string.Format("{5} - {0}{1}{2}{3}{4} </br> ",
_firstname,
_Year,
_coursename,
_credits,
_mark,
counter);
counter++;
}
Response.Write(result);
reader.Close();