This is my code...Dim strConnString As String = ConfigurationManager.ConnectionStrings _ ("ConnectionString1").ConnectionString Dim sqlConn As New SqlConnection(strConnString) Dim DR As SqlDataReader Try Dim sqlCmd As New SqlCommand("SELECT Video FROM tbl_tmp_CP WHERE CP = " & Request.QueryString("CP").ToString, sqlConn) sqlCmd.CommandType = CommandType.Text sqlConn.Open() DR = sqlCmd.ExecuteReader() If DR.HasRows Then If DR.GetValue(0) Is DBNull.Value Then ----->>> Error Here Return "0" Else Return Format(CStr(DR.GetValue(0)), "#,###.00") End If Else Return Nothing End If DR.Close() sqlConn.Close() Catch ex As Exception If Not DR Is Nothing Then If Not DR.IsClosed Then DR.Close() End If End If If Not sqlConn.State = ConnectionState.Closed Then sqlConn.Close() End If Return "" End Try
When I run the above code I get the error Invalid attempt to read when no data is present when I get to the point stated above.I have tried the Select Statement in Query analyzer and I get...Video-----0The reader says that it has rows but I cannot access any of the data.