I have the following piece of code. The SQL query returns me two rows of value.
However, when I involve the method cmd.ExecuteReader(); the application only returns the first row of values.
How do I go about resolving this? Is it something wrong with the cmd.Parameters.AddWithValue method? Please help!
sqlQuery = "select name, data,data2 from surgicalfiledemo where id = '2'";
SqlCommand cmd = new SqlCommand(sqlQuery, con);
cmd.Parameters.AddWithValue("id", surgicalGridView.SelectedRow.Cells[1].Text);
SqlDataReader dr = cmd.ExecuteReader();
if (dr.Read())
{
HttpContext.Current.Response.ClearContent();
HttpContext.Current.Response.AddHeader("content-disposition", "attachment;filename=" + dr["name"].ToString() + ".xls");
HttpContext.Current.Response.ContentType = "application/excel";
Response.Charset = "";
Response.Cache.SetCacheability(HttpCacheability.NoCache);
Response.Write(dr["data"] + "\t");
Response.Write(dr["data2"] + "\t");
Response.End();
}
while (dr.Read()) { ...... }code snippet. Right now - you're only reading a single row from the data reader ....