dr.Read()

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
}
 
W

William \(Bill\) Vaughn

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

William \(Bill\) Vaughn

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

Jim Rand

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"
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top