[英]How do I reverse ORDER BY to give me the smallest instead of the largest?
下面的方法有一个命令,可以在文本框中打印出我的数据库的行。 它只打印出 maxDataBaseListings # 行。 但是,它会从最旧的日期到最新的日期打印出来。 如果 maxDatabaseListings 为 10,并且我的第 11 个条目的日期比我的第 10 个条目新,则不会显示。
如何反转 ORDER BY 命令以首先显示最新日期? 这样,当该方法被调用时,它会用最先列出的最新日期刷新表。
public void refreshListing(TextBox inputTextBox, TextBox inputMaxDatabaseListings)
{
if (currentlyConnectedToADatabase)
{
maxDatabaseListings = returnMaxListings(inputMaxDatabaseListings.Text, numberOfDatabaseListings);
inputTextBox.Text = "";
cnn.Open();
//COMMAND HERE
command = new SqlCommand("SELECT * FROM tcn.Demo ORDER BY DateTimeOfInsertion, SomeNumber, SomeText, AnotherNumber", cnn);
reader = command.ExecuteReader();
theTextBox = inputTextBox;
int i =0;
if (reader.HasRows)
{
while (reader.Read() && i < maxDatabaseListings)
{
string printString = int.Parse(reader["SomeNumber"].ToString()) + " " + reader["SomeText"].ToString() + " " + int.Parse(reader["AnotherNumber"].ToString()) + " at " + reader["DateTimeOfInsertion"].ToString() + Environment.NewLine;
theTextBox.AppendText(printString);
i++;
}
}
else
{
Console.WriteLine("No rows found.");
}
reader.Close();
cnn.Close();
}
else
{
MessageBox.Show("You must first connect to a database!");
}
}
ORDER BY column_1 DESC, column_2, column_n
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.