Basically use the classic ASP\PHP\Spaghetti code approach.
First of all, place your code in one public method that returns a string.
The method:
public string getWhileLoopData()
{
string htmlStr = "";
SqlConnection thisConnection = new SqlConnection(dbConnection);
SqlCommand thisCommand = thisConnection.CreateCommand();
thisCommand.CommandText = "SELECT * from Test";
thisConnection.Open();
SqlDataReader reader = thisCommand.ExecuteReader();
while (reader.Read())
{
int id = reader.GetInt32(0);
string Name = reader.GetString(1);
string Pass = reader.GetString(2);
htmlStr +="
"+id+""+Name+""+Pass+""}
thisConnection.Close();
return htmlStr;
}
Then you can use the tag in ASP.NET that is equal to
It should look something like this:
ID | Name | Pass |
There is also the option to use an repeater control and bind the data from your DB to an Item Template of your liking.