我如何反转 ORDER BY 给我最小的而不是最大的?
How do I reverse ORDER BY to give me the smallest instead of the largest?
下面的方法有一个命令,可以在文本框中打印出我的数据库的行。它只打印出 maxDataBaseListings # of rows。但是,它会将它们从最早的日期打印到最新的日期。如果 maxDatabaseListings 为 10,而我的第 11 个条目的日期比第 10 个条目的日期更新,则不会显示。
如何反转 ORDER BY 命令以首先显示最新日期?这样,当调用该方法时,它会刷新 table,并首先列出最新的日期。
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
下面的方法有一个命令,可以在文本框中打印出我的数据库的行。它只打印出 maxDataBaseListings # of rows。但是,它会将它们从最早的日期打印到最新的日期。如果 maxDatabaseListings 为 10,而我的第 11 个条目的日期比第 10 个条目的日期更新,则不会显示。
如何反转 ORDER BY 命令以首先显示最新日期?这样,当调用该方法时,它会刷新 table,并首先列出最新的日期。
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