Windows Forms
A set of .NET Framework managed libraries for developing graphical user interfaces.
1,839 questions
This browser is no longer supported.
Upgrade to Microsoft Edge to take advantage of the latest features, security updates, and technical support.
I would like to read all of the values from the column name "seatNo" and store those values within a list. I've done most of the code but i have absolutely no idea how to actually store the values. Can someone help?
Here is what i have so far:
private List<string> seatNumbers = new List<string>();
public void PreparingSeatUI()
{
string GetDataQuery = "SELECT seatNo FROM bookings where schedule = @scheduleId";
cmd = new SqlCommand(GetDataQuery, _IsqlDataFunctions.GetConnection());
cmd.Parameters.AddWithValue("@scheduleId", txtSchedule.Text);
_IsqlDataFunctions.GetConnection().Open();
var reader = cmd.ExecuteReader();
while (reader.Read())
{
seatNumbers.Add() // not sure how to add each value here
{
});
}
_IsqlDataFunctions.GetConnection().Close();
}
Thankyou
You have a data type mismatch; "seatNo" in database is integer and in your code it's string
Anyway, this should work:
seatNumbers.Add(reader.GetInt32(0).ToString());