problem1:
thanks Frank and Bill.
sorry for not making my requirement clear.
my sql query is
sql = "SELECT Value from myTable";
cmd = new SqlCommand(sql);
SqlDataReader reader = cmd.ExecuteReader();
double myFinalValue = 0.0;
do
{
while(reader.Read)
{
myFinalValue = myFinalValue + reader.GetDouble(0);
}
}while (reader.NextResult();
my requirement is values from all different rows should be
summed and returned based on a few other business rules.
I'm not able to get the reader move past the first record.
problem2:
Now I have a new problem. I was trying hard to resolve the
above problem and apparently I broke another place.
I'm using datareader to read a 1 row result from a query.
sql = "Select name from myTable where id = 1";
SqlCommand cmd = new SqlCommand(sql);
SqlDataReader reader = cmd.ExecuteReader();
while(reader.Read())
{
if(!reader.IsDBNull(0))
myName = reader.GetString(0);
}
reader.Close();
cmd.Dispose();
This was working fine until I don't know what I broke.
Although this query returns rows from SQL query analyzer,
reader.HasRows property returns 0 and the while loop is
never executed.
Any thoughts? Thanks a lot.
-----Original Message-----
Hi all
I'm trying to traverse through the results from a query
that returns more than 1 row. The data reader reads only
the first row. The following code doesn't work. Let me
know what's wrong.
do
{
while(reader.read)
{
x += y;
reader.NextResult();
}
}while reader.NextResult();
I've tried a few different ways. Nothing seems to work.
Finally, after trying a few different things, now it
doesn't seem to read any of the rows. Thanks a lot for
your help.
.