我只有一個文件在我的數據庫中,從組2中,當我嘗試檢索這個組編號爲2的最後5個文件時,我檢索這個文件4次?C#循環,SQL和檢索信息
我知道這是我的循環中的一個問題,但我不明白哪裏是檢索4次具有相同ID的同一文件的問題。
這是我使用的代碼!
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>"));
}
如果你不使用任何字段,你爲什麼在你的查詢中包含'Groups'表? – Marco 2012-02-13 10:18:23
你正在做一個奇怪的,不合格的,加入這裏...通常解釋大部分重複。 – 2012-02-13 10:19:20
@Shai:我認爲這是錯誤的答案。事實上,修復一個不同的選擇是一個典型的錯誤。 – 2012-02-13 10:19:54