I am trying to get the data from my SQL table to display onto my View page which I would like to display the contents from the table
I can currently read the items in the database using the code below
SqlConnection connection = new SqlConnection(VV);
using (connection)
{
//LIMIT 5 DESC from ID which shows last 5 work outs
SqlCommand myCommand = new SqlCommand("SELECT * FROM Strength", connection);
connection.Open();
SqlDataReader read = myCommand.ExecuteReader();
if (read.HasRows)
{
while (read.Read())
{
Id = read["Id"].ToString();
System.Diagnostics.Debug.WriteLine(Id);
Weight = read["Weight"].ToString();
System.Diagnostics.Debug.WriteLine(Weight);
Rep = read["Rep"].ToString();
System.Diagnostics.Debug.WriteLine(Rep);
}
}
else
{
Console.WriteLine("nothing");
}
read.Close();
}
And now I want to display this in a HTML table on the view. I have tried a few things such as
ViewBag.HtmlStr = "<table class='table table-striped top-buffer'"
+ "style='width:300px'>"
+ "<tr><th>Weight(KG)</th><th>Reps</th></tr>"
+ "<tr><td>" + TableWeight + "</td>"
+ "</tr><tr><td>" + TableRep + "</td></tr></table>";
However it is only giving me one row.
Any advice? Many thanks