我有以下一段代码。SQL 查询返回两行值。但是,当我涉及该方法时cmd.ExecuteReader();
,应用程序仅返回第一行值。
我该如何解决这个问题?方法有问题吗cmd.Parameters.AddWithValue
?请帮忙!
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();
}