I have only 1 file in my database, from the group 2 and when I try to retrieve the 5 last files of this group number 2 I retrieve this file 4 times ?
I know it’s a problem in my loop, but I can’t see where is the problem of retrieving 4 times the same file with the same ID .
This is the code I use !
dynamic queryString = ("SELECT Files.Id, Files.Name, Files.Date, Files.Path, Files.[Group] FROM Files,Groups WHERE Files.[Group] = " + param + "ORDER BY Files.Id DESC");
SqlCommand theCommand = new SqlCommand(queryString, dbConnection);
dbConnection.Open();
SqlDataReader reader = theCommand.ExecuteReader();
int i = 0;
while (reader.Read())
{
i++;
HyperLink fileHl = new HyperLink();
fileHl.Text = reader["Name"].ToString();
fileHl.CssClass = "filelink" + i;
fileHl.ID = reader["Id"].ToString();
fileHl.NavigateUrl = String.Format("downloading.aspx?path={0}&file={1}", reader["Path"], reader["Name"]);
linktofiles.Controls.Add(fileHl);
linktofiles.Controls.Add(new LiteralControl("<br>"));
}
Remove the
Groupstable from your select. You are not using it, and you are not joining correctly, so it will give you unwanted results. Furthermore, don’t usedynamicas the type for your connection string. Usestring.