I am trying to make a utility for kindergarten kids that will randomly select them for stuff toys. I have an entity/POCO class and a DAL class. Then at WinForm, I am doing the random selection.
I am getting the object from the following code but I want the RollNumber field and pass it to random class.
Participants class
public class Participants
{
public string RollNumber { get; set; }
public string Name { get; set; }
}
DAL class
public List<Participants> GetAllParticipants()
{
List<Participants> participants = new List<Participants>();
string Query = String.Format("SELECT rollnumber, name FROM students);
newConnection.OpenConnection();
SqlCommand command = new SqlCommand(Query,
newConnection.SQLConnectionInstance);
SqlDataReader dataReader = command.ExecuteReader();
Participants participantList = null;
while (dataReader.Read())
{
participantList = new Participants();
if (System.DBNull.Value != dataReader["rollnumber"])
{
participantList.RollNumber =
(dataReader["rollnumber"].ToString());
}
if (System.DBNull.Value != dataReader["name"])
{
participantList.Name = (dataReader["name"].ToString());
}
participants.Add(participantList);
}
return participants;
}
This is how I am trying to get the rollnumber field
public string RandomString() {
ParticipantRepository participantRepository = new ParticipantRepository();
var listx = participantRepository.GetAllParticipants();
var listP = new List<Participants>();
var mySKUs = listP.Select(l => l.rollnumber).ToString();
var zoo = mySKUs.OrderBy(x => random.Next());
var xoo = zoo.ToString();
return xoo;
}
And trying to show it in a label at timer_tick
event but this is what I am getting instead System.Linq.OrderedEnumerable'2[System.Char, System.Int32]
Aucun commentaire:
Enregistrer un commentaire