Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Datareader: Can't get HASROWS to work

Status
Not open for further replies.

olypost

Programmer
Apr 15, 2005
43
US
I need to query a sql server table, and if the query returns no rows, then submit a second query.

The only column returns is a binary value, datatype of ntext.

Dim conn As String = "my connection string"
Dim cnn As New SqlConnection(conn)
Dim cmd As New SqlCommand("select binary_col from t1 where col1 =" & var, cnn)
cnn.Open()
Dim dr As SqlDataReader = cmd.ExecuteReader()
If dr.HasRows Then
dr.Read()
<snipped out>
else
<code for 2nd query here>
end if


Whenever the value of var causes the query to return no rows,
I can't get it to ever go into the else condition and submit the
2nd query.

I would ideally prefer always issueing one query, but the ntext in the sql prevents me from doing a union, for example.

Do I have something missing or out of order?

Thanks.
 
Do I have something missing or out of order?

Quite possibly but you do have the wrong forum. This looks like .NET not ASP to me. Your best bet is to ask in the correct forum:

* forum796 for VB.NET
* forum855 for ASP.NET


Tony
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top