我有这张表..我想提取一个特定的数据..
让我们说..我有Home Depot作为按钮。如何将CameraID
的值拉2并将其放在变量上?
像这样......
'dim foo as string = cameraID where MarkerName is Home Depot
答案 0 :(得分:0)
鉴于您使用DataTable
,例如:
' example DataTable '
Dim dt = new DataTable()
dt.Columns.Add("cameraID", gettype(integer))
dt.Columns.Add("MarkerName", gettype(string))
dt.Rows.Add(new object() {2, "Home Depot"})
dt.Rows.Add(new object() {1, "CSI"})
您可以使用LINQ查询:
' foo is now 2 '
Dim foo = dt.AsEnumerable() _
.Where(function(row) row("MarkerName") = "Home Depot") _
.Select(function(row) row("cameraID")) _
.Single()
或Select
方法来过滤DataTable
:
' foo2 is now 2 '
Dim foo2 = dt.Select("MarkerName = 'Home Depot'")(0)("cameraID")