Storing values from a single column within a list.

sock1992

Well-known member
Joined
May 20, 2020
Messages
107
Programming Experience
Beginner
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

1616585888335.png


Here is what i have so far:

C#:
 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();
            
        }
 
I apologize for the what I'm going to write below as being harsh, but I can't convey in strong enough words that you probably need to step back and take time to understand the code you are writing and the concepts behind the code.

OMG! Dude! So you were just doing cargo cult programming when you wrote the following code in your other thread:
C#:
while (reader.Read())
{
    userDetails.Add(new CustomerLogin()
                    {
                        CustomerId = reader.GetInt32(0),
                        FirstName = reader.GetString(1),
                        LastName = reader.GetString(2),
                        Address = reader.GetString(3),
                        ContactNumber = reader.GetString(4),
                        Email = reader.GetString(5),
                        Password = reader.GetString(6),             
                    });
}

It pretty obvious you don't understand what reader.GetInt32() was doing if you were using it in your other thread, but can figure out how to get the seatNo column in this thread.

The best thing I can recommend at this point is to take time to read the documentation behind the various methods you are calling, and try to do google searches on some the concepts and techniques that you are using.

Now to temper the harshness above with a little encouragement:

You've reached the point in writing code where you have picked up enough skills to start to be dangerous. Just like in most martial arts, where the red belt symbolizes where a student has enough skills to be dangerous, but is still on the path of learning and growth, it feels like you are on that same journey. Kudos to you for your progress! Now we need to help you completely earn that red belt, and then get you moving to your brown belt, and eventually your black belt. Admittedly, I don't always have the best disposition to be a good mentor, but there are others here on this forum who are consistently much better than I am. Hopefully, we can get you to where you need to be.
 
I apologize for the what I'm going to write below as being harsh, but I can't convey in strong enough words that you probably need to step back and take time to understand the code you are writing and the concepts behind the code.

OMG! Dude! So you were just doing cargo cult programming when you wrote the following code in your other thread:
C#:
while (reader.Read())
{
    userDetails.Add(new CustomerLogin()
                    {
                        CustomerId = reader.GetInt32(0),
                        FirstName = reader.GetString(1),
                        LastName = reader.GetString(2),
                        Address = reader.GetString(3),
                        ContactNumber = reader.GetString(4),
                        Email = reader.GetString(5),
                        Password = reader.GetString(6),          
                    });
}

It pretty obvious you don't understand what reader.GetInt32() was doing if you were using it in your other thread, but can figure out how to get the seatNo column in this thread.

The best thing I can recommend at this point is to take time to read the documentation behind the various methods you are calling, and try to do google searches on some the concepts and techniques that you are using.

Now to temper the harshness above with a little encouragement:

You've reached the point in writing code where you have picked up enough skills to start to be dangerous. Just like in most martial arts, where the red belt symbolizes where a student has enough skills to be dangerous, but is still on the path of learning and growth, it feels like you are on that same journey. Kudos to you for your progress! Now we need to help you completely earn that red belt, and then get you moving to your brown belt, and eventually your black belt. Admittedly, I don't always have the best disposition to be a good mentor, but there are others here on this forum who are consistently much better than I am. Hopefully, we can get you to where you need to be.
n
 
Last edited:

Latest posts

Back
Top Bottom