In ASP.NET, how come .HasRows does not work properly?
Posted on 2011-03-18
I have the following code:
Using connection As New SqlConnection(ConfigurationManager.AppSettings("ConnectionString1"))
Dim command As New SqlCommand(queryString, connection)
command.Parameters.Add("@param_ClientID", Data.SqlDbType.NVarChar, 10).Value = ClientID.Trim.ToString
Dim reader As SqlDataReader = command.ExecuteReader()
If reader.HasRows Then
stPrompt = "Client Id Check: " & reader(0).ToString
I am working with test data so i know the client does not exist. When it gets to "If reader.HasRows" it is always coming up as TRUE. When it gets to the "reader(0).ToString", it gives an error "Invalid attempt when no data is present."
Am I using .HasRows properly?
Should I do something other than "SqlDataReader = command.ExecuteReader()"?