1

while ステートメント内で for each ステートメントを実行しようとしていますが、for each ステートメント内でコードを実行していません。「値」が何らかの形で割り当てられていないと思いますか?

cmd = New SqlCommand
cmd.Connection = Con
cmd.CommandText = "SELECT [Physician First Name], [Physician Last Name], [Recipient Primary Business Street Address Line 1], [Recipient City], [Recipient State], [Recipient Zip Code], Notes_ConsultingFee, [Total Amount of Payment]  FROM tblData WHERE ReferenceNumber = @ReferenceNumber"
cmd.Parameters.Add(New SqlParameter("@ReferenceNumber", (ReferenceTextBox.Text)))
Dim reader As SqlDataReader = cmd.ExecuteReader()

While reader.Read()
    For Each value As Object In reader

        Dim firstName = reader.GetString(0)
        Dim LastName = reader.GetString(1)
        Dim Address = reader.GetString(2)
        Dim City = reader.GetString(3)
        Dim State = reader.GetString(4)
        Dim Zip = reader.GetString(5)
        Dim Notes = reader.GetString(6)
        Dim Amount As Decimal = reader(7)
        Session("PDF") &= firstName & " " & LastName & Environment.NewLine & Address & Environment.NewLine & City & "," & State & " " & Zip & Environment.NewLine & "Consulting Fee Amount: " & Amount & Environment.NewLine & "Notes: " & Notes
    Next
End While
4

1 に答える 1

6

For Eachループはまったく必要ありません。Whileループは次のようにリーダーを反復処理します。

While reader.Read()
    Dim firstName = reader.GetString(0)
    Dim LastName = reader.GetString(1)
    Dim Address = reader.GetString(2)
    Dim City = reader.GetString(3)
    Dim State = reader.GetString(4)
    Dim Zip = reader.GetString(5)
    Dim Notes = reader.GetString(6)
    Dim Amount As Decimal = reader(7)
    Session("PDF") &= firstName & " " & LastName & Environment.NewLine & Address & Environment.NewLine & City & "," & State & " " & Zip & Environment.NewLine & "Consulting Fee Amount: " & Amount & Environment.NewLine & "Notes: " & Notes
End While
于 2013-09-24T17:51:03.967 に答える