Hello
Let me show you the code I'm trying to do and then I'll ask the question:
So, query database and loop through the results and write all results to a label showing lots of pictures UNLESS there is only 1 result, where I want to forward to another page. The obvious error is when it tries to forward to another page it can't because it can't read the dataReader as it is outside the loop!
Any ideas?
My thoughts were either:
a) requery database with a count function( eg, SELECT COUNT (*) WHERE xyz = 'xyz' etc) - not keen on this as I don't want to re-open a connection
b) assign all the partnumbers the reader reads to a session variable
c) is it possible to write a dataReader to a dataset and then query the dataset or do I need to use the dataAdapter for that?
Thanks
Dave
Let me show you the code I'm trying to do and then I'll ask the question:
Code:
SqlDataReader rdr = null;
SqlConnection conn = new SqlConnection(strConn);
string strSQL = "SELECT * FROM View_ProductRange WHERE "+sqlSearch+"";
SqlCommand cmd = new SqlCommand(strSQL, conn);
conn.Open();
rdr = cmd.ExecuteReader();
int rdrCount = 0;
while (rdr.Read())
{
lbProducts.Text += "<img src='"+rdr["Location"] + "/images/"+rdr["PartNumber"]+".gif' alt='' class='thumb-outerbox' />
rdrCount= rdrCount + 1;
}
if (rdrCount == 1)
{
Response.Redirect("http://www.site.com/search.aspx?pn="+rdr["PartNumber"]);
}
conn.Close();
Any ideas?
My thoughts were either:
a) requery database with a count function( eg, SELECT COUNT (*) WHERE xyz = 'xyz' etc) - not keen on this as I don't want to re-open a connection
b) assign all the partnumbers the reader reads to a session variable
c) is it possible to write a dataReader to a dataset and then query the dataset or do I need to use the dataAdapter for that?
Thanks
Dave
Comment