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.
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.