如何查找数据集的行号 vb.net
How to find the row number of a dataset vb.net
我正在尝试查找包含字段 "Name" 中的项目 "Rushil" 的数据集的行号。我正在研究如何做到这一点,我遇到了 Datatable.Select 方法。
查找行号的过滤表达式是什么?我将如何在 vb.net 中执行此操作?
使用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服务器
根据你的问题我假设table中只有一个'Rushil',然后我会告诉你如何获取[=29=中单行的行号].
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
我正在尝试查找包含字段 "Name" 中的项目 "Rushil" 的数据集的行号。我正在研究如何做到这一点,我遇到了 Datatable.Select 方法。
查找行号的过滤表达式是什么?我将如何在 vb.net 中执行此操作?
使用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服务器
根据你的问题我假设table中只有一个'Rushil',然后我会告诉你如何获取[=29=中单行的行号].
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