This line on my .aspx page was put there automatically "DataSourceID="SqlDataSource1" Which is what I deleted.
Then I got an error about the reader that was still opened...
I got it work as follows:
int DisplayTable()
{
using (SqlConnection myConnection2 = new SqlConnection(DBConn))
{
SqlCommand MyCommand2 = new SqlCommand("SELECT * from TheTableName;", myConnection2);
myConnection2.Open();
SqlDataReader reader = MyCommand2.ExecuteReader();
GridView1.DataSource = reader;
GridView1.DataBind();
reader.Close();
return MyCommand2.ExecuteNonQuery();
}
}
As a student who has only just started programming, I would like to thank everyone who has given me such good answers that apply to my questions, if only there was a way I could let them know how gratefull I am.