I am trying to loop through a DB and create a button for each row based on my query. I should be getting 3 buttons in return however only one is being created.
DataTable dt = new DataTable();
con.Open();
string TeamID = (string)Session["TeamID"];
SqlDataReader myReader = null;
SqlCommand myCommand = new SqlCommand("SELECT * FROM Players1 WHERE
TeamID = " + teamID, con);
myCommand.Parameters.AddWithValue("@TeamID", TeamID);
myReader = myCommand.ExecuteReader();
while (myReader.Read())
{
foreach (Object ob in myReader)
{
Button1.Text = "" + (myReader["Name"].ToString());
}
}
I should be getting 3 buttons based on the data in my DB