string query = q;
SqlCommand queryCommand = new SqlCommand(query, Connection);
SqlDataReader queryCommandReader = queryCommand.ExecuteReader();
DataTable dataTable = new DataTable();
dataTable.Load(queryCommandReader);
List<string> rowText = new List<string>();
for (int i = 0; i < 4; i++)
{
foreach (DataColumn columns in dataTable.Columns)
{
rowText.Add(dataTable.Rows[i][columns.ColumnName] + "");
}
}
在此示例中,我从数据库中获取 4 行 for 循环中的条件 i < 4 我想获得真正的行数而不仅仅是 4