I'm trying to translate between php and ASP.Net. In php I can connect to the database, run a query, and print out the results in html tags as shown below:
$query="SELECT * FROM comments;";
$result=$mysqli->query($query);
while($row=$result->fetch_object()) {
echo "<div class=\"comment\">";
echo "<h1>".$row->title."</h1>";
echo "<p>".$row->comment."</p>";
echo "</div>";
}
?>
In ASP.NET with c#, how would I do this?
I'm aware I have to use SqlConnection() and SqlCommand() and possibly SqlDataReader(). But how do I make ASP.NET do what I have php doing above? And where do I place the code? In the Page Load method? Or in the middle of the html?
I have looked a using grid views and table views to pull data from the database, however they don't allow me to make the page look how I want. I want data from the database to populate a html template I mark up, not some predefined grid or table structure.
Thanks