dr.Read()

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hello Everyone:

I have a feeling this is very basic, and something I am just overlooking.
The dr.Read() ALWAYS is being translated to false in the code below. I print
out the sSQL statement using the watch window, and paste that into Query
Analyzer: and I confirm the data does indeed exist. What am I missing?
Why, regardless of the data, does my dr.Read() alway equal false?

-----------------------------------------------------------------------------------------------
CODE SNIPPE
-----------------------------------------------------------------------------------------------
sSQL = "SELECT i_OrderID FROM tOrder WHERE sPOrder = " + sPONumber;
SqlConnection oConn = new SqlConnection(connStr());
SqlCommand oCommand = new SqlCommand(sSQL, oConn);
oConn.Open();
SqlDataReader dr = oCommand.ExecuteReader();
if(dr.Read())
{
....Code Removed
}
else
{
....Code Removed
}
 
See my reply on rowset-less resultsets...

--
____________________________________
William (Bill) Vaughn
Author, Mentor, Consultant
Microsoft MVP
www.betav.com
Please reply only to the newsgroup so that others can benefit.
This posting is provided "AS IS" with no warranties, and confers no rights.
__________________________________
 
This behavior is by design. When you execute any query that does not return
a rowset, the DataReader returns as "closed" (Dr.Read = False). Step to the
next resultset or add SET NOCOUNT ON in your query or SP to drop rowsetless
resultsets.

hth

--
____________________________________
William (Bill) Vaughn
Author, Mentor, Consultant
Microsoft MVP
www.betav.com
Please reply only to the newsgroup so that others can benefit.
This posting is provided "AS IS" with no warranties, and confers no rights.
__________________________________
 
I think your where clause is failing. If the PONumber is a string, where
are your ' ' ?

Try using a paramater collection with SQL that looks like:

"SELECT i_OrderID FROM tOrder WHERE sPOrder = @PONumber"
 
Back
Top