简体   繁体   中英

SQLDataReader not reading using VB.net

I am using a SQLDataReader to display the results of my stored procedure, however, I have been unable to have it display any records. I am not generating an error and if I write out reader.hasrows.tostring() it returns true so I know it is returning a single row as intended. I know I have data in all columns to display. Any guidance would be appreciated.

        Dim sqlcon2 As SqlConnection = New SqlConnection(Session("ConnStrEP"))
        sqlcon2.Open()

        Dim sqlcomm2 As SqlCommand = New SqlCommand("up_GetGenInfo_E1_01_02", sqlcon2)
        sqlcomm2.CommandType = Data.CommandType.StoredProcedure
        sqlcomm2.Parameters.Add("AppNo", AppNo)
        sqlcomm2.Parameters.Add("RevNo", RevNo)
        Dim dt As SqlDataReader = sqlcomm2.ExecuteReader()
        dt.Read()

        Response.Write(dt.Item("PrName").ToString())


        dt.Close()
        sqlcomm2.Dispose()
        sqlcon2.Close()

Do it in a following way:

 Do While dt.Read()
    Response.Write(dt.Item("PrName").ToString())
 Loop

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM