I have a C# SQL query for my asp.net page which queries the database using a value stored in the session of my page (called tournyName). I have the query working, and I am using a SqlDataReader (called myReader) to read the results of the query. I cant however get the results to display on the HTML area of my page.
I have been piecing together bits of code that I have found from other peoples questions and the code at this point is incomplete. It looks something like this:
C# (snppit):
conn.Open();
query = "SELECT GamePlayer1 AS [Player 1], GamePlayer2 AS [Player 2], GamePlayer1Score AS [Score1], GamePlayer2Score AS [Score2] FROM Games WHERE (TournyName = '@TournyName')";
com = new SqlCommand(query, conn);
com.Parameters.Add(new SqlParameter("@TournyName", SqlDbType.VarChar, 200));
com.Parameters["@TournyName"].Value = Server.HtmlDecode(tournyName.Trim());
SqlDataReader myReader;
myReader = com.ExecuteReader();
myRepeater.DataSource = myReader;
myRepeater.DataBind();
And my HTML, where I would like to display the results:
<asp:Repeater id="myRepeater" runat="server">
<HeaderTemplate><table border="1"></HeaderTemplate>
<ItemTemplate>
<tr><td>
</td>
<td>
<%# Eval('Player 1')%>
</td>
<td>
<%# Eval('Player 2')%>
<td>
<%# Eval('Score1')%>
</td>
<td>
<%# Eval('Score2')%>
</td>
</tr>
</ItemTemplate>
<FooterTemplate></table></FooterTemplate>
</asp:Repeater>
No matter what I try, the page just shows up as blank. Can anybody enlighten me as to how I would display this?
There are a couple of things:
<%# Eval("Player 1")%>Also, remember to Dispose your connection, command and SQLReader.