我试图遍历这个列表并获得一次一个医生的值。通过列表进行迭代
在excel文档中,每个医生都有多个医生,但我希望输出是一个医生。
在excel文档中,它会出现HILL CANN CANN HILL,这就是我现在回来的。
但我想每个医生迭代所以它会去山连山CANN CANN
Dim physname As New List(Of String)()
'Get all of the data from tblPhysician that you will use and put into a list for searching the excel file
Sql = "select * from tblPhysician "
conn = New OdbcConnection(connectionString)
conn.Open()
comm = New OdbcCommand(Sql, conn)
dr = comm.ExecuteReader()
'Populate the physname list with the doctors names
While (dr.Read())
physname.Add(dr("PhysicianName").ToString())
End While
range = oxlsheet.UsedRange
For rcnt = 1 To range.Rows.Count
For ccnt = 2 To 6
varray = CType(range.Cells(rcnt, ccnt), Excel.Range)
If (IsNumeric(varray.value)) Then
temp = varray.value.ToString
Else
temp = varray.value
End If
'Iterate through physname list for each doctor in the list
For Each doctor As String In physname
If (rcnt > 8) Then
If (IsNumeric(varray.Columns(4).value)) Then
temp2 = varray.Columns(4).value.ToString
Else
temp2 = varray.Columns(4).value
End If
'If the name in the excel column matches, write out the name and value
If (temp2 = doctor) Then
Console.WriteLine(varray.Columns(4).value)
Console.WriteLine(varray.Columns(5).value)
Console.ReadLine()
End If
End If
Next
Next
Next
您是否需要*在*中阅读它们,并在阅读时打印每个项目,或者您可以阅读所有内容,进行排序,然后输出每个项目?另外我猜这是作业。 – helrich 2014-09-25 17:54:31
好吧,我将最终在Excel文件中添加一些其他信息。所以我认为通过这样的每位医生迭代会给我提供每名医生每PER时间的信息。不,不是功课。只是想扩大我对vb的了解 – FoxMcCloud 2014-09-25 18:00:24