我正在尝试查找包含该项目的数据集的行号" Rushil"在现场"姓名"。我正在研究如何做到这一点,我遇到了Datatable.Select方法。
过滤器表达式是什么来查找行号?我将如何在vb.net中执行此操作?
答案 0 :(得分:1)
使用 vb.Net
'assume that you want to start indexing from 1
Dim rowNum As Integer
rowNum = 0
For Each row As DataRow In dtDataTable.Rows
If LCase(Trim(row.Item("Name"))) = LCase("Rushil") Then
Exit For
End If
rowNum += 1
Next row
If rowNum > 0 Then
MsgBox("Rushil was found at " + Str(rowNum + 1))
Else
MsgBox("Rushil was not found")
End If
使用 SQL SERVER
根据你的问题,我假设表格中只有一个'Rushil',然后我会告诉你如何获得表格中单行的行号。
select rank
from(select rank() OVER (ORDER BY e.[name]) as rank,e.[name]
from example e)z
where [name]= 'Rushil'
/* result : */
rank
2
如何处理答案
create table example(
[name] varchar(10),
password varchar(8)
)
insert into example values('veteranlk','password')
insert into example values('sqlfiddle','wasspord')
insert into example values('Gholkar','qwedsadd')
insert into example values('Rushil','ssdwwaaa')
insert into example values('Shirul','wasspord')
select rank() OVER (ORDER BY e.[name]) as rank,e.[name]
from example e
order by rank
/* result : */
rank name
1 Gholkar
2 Rushil
3 Shirul
4 sqlfiddle
5 veteranlk