我正在尝试对数据库表运行查询,并按字母顺序返回结果,但是当我运行以下语句时,它将以与数据库中显示的方式相同的方式返回所有内容。我正在办公室小组做一个订单,根据我的理解,它应该按字母顺序返回结果顺序。
SELECT
OfficeGroupID, OfficeGroup
FROM
tblofficegroup
INNER JOIN
tblRegion ON tblOfficeGroup.RegionID = tblRegion.RegionID
WHERE
ISNULL(tblofficegroup.Hide, 0) = 0
AND ISNULL(tblRegion.Hide, 0) = 0
AND OfficeGroupID <> 18 --'Not Mapped'
ORDER BY
OfficeGroup -- this should return it in alphabetical order but nogame.
-- I also tried passing the ASC command but neither worked
这是数据库中的表,我在网页上显示查询,它显示的顺序与表中显示的顺序相同。我使用ASC
,但没有运气,这是一个字符串类型(varchar(32)
)。
这是我的网页查询功能,我没有看到任何问题:
public static List<Market> GetMarketGroup()
{
List<Market> regionList = new List<Market>();
using (SqlConnection connection = new SqlConnection(_constring))
{
StringBuilder sqlCommandBuilderTxt = new StringBuilder();
sqlCommandBuilderTxt.Append("SELECT OfficeGroupID,OfficeGroup FROM tblofficegroup INNER JOIN tblRegion ON tblOfficeGroup.RegionID = tblRegion.RegionID WHERE ISNULL(tblofficegroup.Hide, 0) = 0 AND ISNULL(tblRegion.Hide, 0) = 0 AND OfficeGroupID <> 18 --'Not Mapped' ORDER BY OfficeGroup ASC ");
SqlCommand sqlCommand = new SqlCommand(sqlCommandBuilderTxt.ToString(), connection);
try
{
connection.Open();
SqlDataReader reader = sqlCommand.ExecuteReader();
while (reader.Read())
{
try
{
Market market = new Market();// instance
market.MarketID = reader.GetInt32(0);
market.MarketGroup = reader.GetString(1);
regionList.Add(market);
}
catch (Exception ex)
{
log.Error(ex);
}
}
reader.Close();
connection.Close();
}
catch (Exception ex)
{
log.Error(ex);
}
}
return regionList;
}
答案 0 :(得分:6)
小心使用您用于执行查询的工具(客户端)。
您使用outFile.open("c:\\games\\minecraft\\test.properties");
来评论语句的一部分,您的客户可以将您的查询包装成一行,然后忽略order by子句
考虑使用其他风格的评论:--