reader.Read()
returns false
if there are no lines to read. Thus, if you want to perform special processing without returning strings, you will need to move this check outside the while
:
if (reader.HasRows()) { while (reader.Read()) { LogMessage("Further Inside Try2 "); byte[] paymentData = (byte[])reader["payment"]; strPaymentData = ASCIIEncoding.Unicode.GetString(paymentData); LogMessage(strPaymentData + " strPaymentData"); } } else { LogMessage("Payment Retrievlal Failed "); }
Now, if , you know that only 1 row is returned (for example, reading on the primary key), you can simplify the code by simply placing reader.Read()
inside if
:
if (reader.Read()) { LogMessage("Further Inside Try2 "); byte[] paymentData = (byte[])reader["payment"]; strPaymentData = ASCIIEncoding.Unicode.GetString(paymentData); LogMessage(strPaymentData + " strPaymentData"); } else { LogMessage("Payment Retrievlal Failed "); }
source share