我从 SQL Server 获取具有动态列数的查询结果,其中列名可变。如何将 datareader 的结果转换为通用列表 List ?
public ? getItems(string orderId)
{
SqlConnection sqlConn = new SqlConnection(conn);
SqlCommand command = new SqlCommand();
SqlDataReader reader;
try
{
sqlConn.Open();
command.Connection = sqlConn;
command.CommandText = "usp_get_orders";
command.CommandType = CommandType.StoredProcedure;
command.Parameters.Add(new SqlParameter("@Id", orderId)));
SqlDataReader reader = command.ExecuteReader();
while (reader.Read())
{
?
}
reader.Close();
}
catch (Exception exp)
{
}
finally
{
command.Dispose();
command1.Dispose();
sqlConn.Close();
sqlConn.Dispose();
}
return ?;
}