如何在SQL Server中按顺序显示记录顺序

问题描述:

我正在使用c#2010创建Windows应用程序,在我的项目中使用数据库sql server,如何使用select命令逐个显示表记录。



I想要我的最终输出

Ex:

Slno

1

2

3

4

5



但是我得到了一个结果

Slno:

1

3

4

2

5

如何解决这个错误



任何人都给我一些想法。



什么我试过了:



如何在sql server中按顺序显示记录顺序

I am creating windows application using c# 2010, in my project using database sql server, how to shown table records display one by one using select command.

I want my final output
Ex :
Slno
1
2
3
4
5

but i got a result
Slno:
1
3
4
2
5
how to solve this error

any one give me some ideas.

What I have tried:

How to display records order by order in sql server

尝试:

Try:
SELECT * FROM MyTable ORDER BY Slno ASC


似乎, Slno 是varc har数据类型。为了能够按正确的顺序对数据进行排序,你必须使用正确的数据类型(int)。



但现在,你可以尝试这样的事情:

Seems, Slno is varchar data type. To be able to sort data in correct order, you have to use proper data type (int).

But now, you can try something like this:
SELECT *
FROM TableName
ORDER CONVERT(INT, Slno) ASC





如需了解更多信息,请参阅: CAST和CONVERT(Transact-SQL) [ ^ ]